Minlength and Maxlength

Discussion in 'HTML' started by Luigi Donatello Asero, Feb 13, 2005.

  1. In html there is an attribute which is called maxlength which let you
    prevent the user to write more than a certain number of characters in a
    form.
    There is no attribute such as minlength.
    Does that mean that the only way
    to prevent the user to write less than a certain number of characters is to
    code it
    in php or some other computer language which let me create a dynamic page
    or do you also have a html option?




    --
    Luigi ( un italiano che vive in Svezia)
    https://www.scaiecat-spa-gigi.com/sv/undervisning-i-italienska.php
     
    Luigi Donatello Asero, Feb 13, 2005
    #1
    1. Advertising

  2. Luigi Donatello Asero wrote:

    > In html there is an attribute which is called maxlength which let you
    > prevent the user to write more than a certain number of characters in a
    > form.
    > There is no attribute such as minlength.


    There is no HTML technique to suggest prevent a form being submitted if the
    user doesn't enter data in a specific form. You could use JavaScript to do
    some form of checking when the onsubmit event of the <form> fires -
    returning false will halt the submission.

    JavaScript is, of course, optional, so you can not depend on it catching
    data which doesn't conform to your needs. For that matter, there is nothing
    stopping the user from overriding any maxlength you specify for any input.

    The only place you can perform sanity checking on the data and be certain
    that the checking has been triggered is within the form processor on the
    server.


    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
     
    David Dorward, Feb 13, 2005
    #2
    1. Advertising

  3. "David Dorward" <> skrev i meddelandet
    news:cunn5j$1po$1$...
    > Luigi Donatello Asero wrote:
    >
    > > In html there is an attribute which is called maxlength which let you
    > > prevent the user to write more than a certain number of characters in a
    > > form.
    > > There is no attribute such as minlength.

    >
    > There is no HTML technique to suggest prevent a form being submitted if

    the
    > user doesn't enter data in a specific form. You could use JavaScript to do
    > some form of checking when the onsubmit event of the <form> fires -
    > returning false will halt the submission.
    >
    > JavaScript is, of course, optional, so you can not depend on it catching
    > data which doesn't conform to your needs. For that matter, there is

    nothing
    > stopping the user from overriding any maxlength you specify for any input.
    >
    > The only place you can perform sanity checking on the data and be certain
    > that the checking has been triggered is within the form processor on the
    > server.


    So, for example by using php and declaring by an "if clause"
    that a variable is accepted as long it is "<" (lower)
    than a certain number.


    --
    Luigi ( un italiano che vive in Svezia)
    https://www.scaiecat-spa-gigi.com/sv/boendeiitalien.html
     
    Luigi Donatello Asero, Feb 13, 2005
    #3
  4. Luigi Donatello Asero

    Toby Inkster Guest

    Luigi Donatello Asero wrote:

    > There is no attribute such as minlength.
    > Does that mean that the only way to prevent the user to write less than
    > a certain number of characters is to code it in php or some other
    > computer language which let me create a dynamic page or do you also
    > have a html option?


    Browsers can happily ignore maxlength, so if length is important to
    yout ;-) you *must* enforce the length limit at the server side.

    If you want a client-side minimum length, you could use Javascript, but
    make sure you back it up with a server-side check.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 13, 2005
    #4
  5. Toby Inkster <> wrote:

    > Browsers can happily ignore maxlength, so if length is important to
    > yout ;-) you *must* enforce the length limit at the server side.


    The conclusion is correct, but I disagree about the premises. The maxlength
    attribute is defined as imposing a limit on the amount of text entered in a
    text input field. It very much looks like browsers are required to
    implement that limit, and that they actually do so.

    But nothing prevents a user from copying a form and editing it, so that the
    maxlength attribute is changed or removed, or writing a completely
    different form with the same action attribute. This could happen out of
    malevolence or cracking attempt, or through an attempt to create a
    "customized form" (e.g. for personal use) plus some technical error in
    doing that. In any case, such possibilities are a fundamental reason for
    making form data handling robust - it should be prepared to literally
    anything, including data that cannot result from submitting the form!

    --
    Yucca, http://www.cs.tut.fi/~jkorpela/
    Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html
     
    Jukka K. Korpela, Feb 13, 2005
    #5
  6. Luigi Donatello Asero

    Toby Inkster Guest

    Jukka K. Korpela wrote:
    > Toby Inkster <> wrote:
    >
    >> Browsers can happily ignore maxlength, so if length is important to
    >> you ;-) you *must* enforce the length limit at the server side.

    >
    > The conclusion is correct, but I disagree about the premises. The
    > maxlength attribute is defined as imposing a limit on the amount of text
    > entered in a text input field. It very much looks like browsers are
    > required to implement that limit, and that they actually do so.


    "can" = "are able to"
    "may" = "are allowed to"

    Browsers *can* happily ignore maxlength.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
     
    Toby Inkster, Feb 13, 2005
    #6
  7. Luigi Donatello Asero, Feb 14, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren Clark
    Replies:
    1
    Views:
    454
    Andrew de la Harpe
    Apr 10, 2004
  2. =?Utf-8?B?bWc=?=

    TextBox - MaxLength property

    =?Utf-8?B?bWc=?=, Apr 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,106
    coollzh
    Apr 11, 2004
  3. hardcoded

    maxlength on multiline textbox

    hardcoded, May 5, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    19,102
    cnicol
    Sep 26, 2007
  4. Patrice
    Replies:
    3
    Views:
    3,041
    bruce barker
    Jun 11, 2004
  5. Don Adams
    Replies:
    1
    Views:
    741
    Don Adams
    Mar 1, 2004
Loading...

Share This Page