
Originally Posted by
deathshadow60
I think you're confusing 'size' and/or CSS width with 'maxlength'.
Maxlength is the maximum number of characters an input can hold. Size and/or CSS width is how big it should be shown on the form... if maxlength is larger than size/width it will scroll sideways as the user types.
<input size="20" maxlength="40" />
or
<input maxlength="40" style="width:12em" />
MaxLength should most always be the maximum length you want to allow in the database. The size attribute or CSS is how you make it pretty, even if the user ends up scrolling sideways inside the field.
That is what I was implying...
Is it breaking some great law to have a Text Box that only holds 20 characters in its visible space but that has a MaxLength of 40 characters, so that if a User wanted to "scroll beyond" the Text-Box's natural size, they could still utilize the full 40 characters in this case?
BTW, I din't know there was a "size" attribute. I have only ever used MaxLength.
You should also keep in mind server side that like all client-side input, it's suspect and/or unenforceable, so you should check the length again on the server before sending it to the query.
Well, I have a Regular Expression on every input like this...
PHP Code:
// ************************
// Validate Form Data. *
// ************************
// Validate First Name.
if (empty($trimmed['firstName'])){
$errors['firstName'] = 'Please enter your First Name.';
}else{
if (preg_match('#^[A-Z \'.-]{2,20}$#i', $trimmed['firstName'])){
$firstName = $trimmed['firstName'];
}else{
$errors['firstName'] = 'First Name must be 2-20 characters (A-Z \' . -)';
}
}
Debbie
Bookmarks