Minlength and Maxlength

  • Thread starter Luigi Donatello Asero
  • Start date
L

Luigi Donatello Asero

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?
 
D

David Dorward

Luigi said:
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.
 
L

Luigi Donatello Asero

David Dorward said:
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.
 
T

Toby Inkster

Luigi said:
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.
 
J

Jukka K. Korpela

Toby Inkster said:
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!
 
T

Toby Inkster

Jukka said:
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.
 
L

Luigi Donatello Asero

Do HSDPA´s users
have access to html pages?
What about pages using php, asp and other programming languages?
Or would you write pages in WAP also for
HSDPA´s users?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top