Jump to content

[SOLVED] field length check


bhavin_85

Recommended Posts

hey guys

 

ive written the following code to check through the lengths that are input into a form, however it doesnt seem to work  ??? i cant figure out where im going wrong

<?
include('config.php');
?>
<html>
<head>
<script type="JavaScript">
function checkInput(){
if((document.registration.username.value.length < 5)||(document.registration.username.value.length < 12)){
  alert ("Please enter a Username between 5 and 12 characters");
  return false;
}
if((document.registration.password.value.length < 5)||(document.registration.password.value.length < 9)){
  alert ("Please enter a Password between 5 and 9 characters");
  return false;
}
}
</script>
<title>Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<table align="center" valign="top" width="700" cols="3">
<tr>
<td align="center" colspan="3">
<font size="+5">Online DVD Shop</font>
</td></tr>
<tr><td>
To register for our online shop please complete the following form
</td></tr>
<tr><td>
<form name="registration" method="post" action="" onSubmit="return checkInput();">
Username: <input name="username" type="text"></input></br></br>
Password: <input name="password" type="text"></input></br></br>
Name: <input name="name" type="text"></input></br></br>
Telephone: <input name="telephone" type="text"></input></br></br>
Email: <input name="email" type="text"></input></br></br>
Address: <input name="address" type="text"></input></br></br>
Zipcode: <input name="zipcode" type="text"></input></br></br>
<input type="submit" value="Submit"></input>
</form>
</td></tr>
</table>
</body>
</html>

 

can any1 tell me what im doing wrong?

 

your help is much appreciated

Link to comment
Share on other sites

you're checking if the length is smaller than 5 and smaller than 12

if((document.registration.username.value.length < 5)||(document.registration.username.value.length < 12)){

 

Notice the < sign before the 5

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.