Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate Length

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
End user will enter a code on form, I need to ensure that this code is no longer than 6 characters.

Thought I could use something like:

if (document.Submit.CODE.length.value > 6 )
{
alert("Please enter a valid code.\n");
document.Submit.CODE.focus();
return;
}

But this errors out, what am I doing wrong ? Help is much appreciated.
 
Take out the .value. .length is a value already. Never too old to learn...
Nico
 
Code:
if (document.Submit.CODE.value.length > 6 ) {
alert("Please enter a valid code.\n");
document.Submit.CODE.focus();
return false;
}
--------------------------------------------------
Goals are dreams with deadlines
 
or...
<form name = &quot;myform&quot;>
<field name = &quot;myfield&quot; maxlength = &quot;6&quot;>
</form> How many software developers does it take to change a light bulb?
None: it works in everyone else’s office, it must work in yours too.
 
Bombboy,
i had to really laugh hard on myself on this one. how easier can it be then just do a &quot;maxlength&quot;??? and yet we bother ourselves with all this javascript if's and else's .... geee --------------------------------------------------
Goals are dreams with deadlines
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top