Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I am writting a javascript for validation of the form. I want to validate the each entry as I enter them, such as once i enter name it should be validated before i enter phone number etc..
For example validation criterias are as follows:
1. name should be more than one character
2. phone number should be atleast 7 digit
3. ssn would be atleast 5 digits.I tried to do following but it won't works.
<form name="form1" enctype="text/plain" method="POST" >*Name: <input TYPE="TEXT" SIZE="30" NAME="myName" onBlur ="validate(this)" >
*Phone: <input TYPE="TEXT" SIZE="15" NAME="phone" onBlur ="validate(this)" >
<input TYPE="BUTTON" VALUE="(e.g 123-455-6789)">*Age: <input TYPE="TEXT" SIZE="3" NAME="age" maxlength="2" onBlur="validate(this)">
*Social Security: <input TYPE="TEXT" SIZE="11" NAME="ssn" onBlur="validate(this)">
<input TYPE="BUTTON" VALUE="(e.g 123-45-6789)"Validate function is as follows:
function validate(field){
if(field.value== document.form1.myName.value){
if(document.form1.myName.value.length <= 1){
alert("Please enter name correctly, Name should be more than one character.");
document.form1.myName.focus();
return false;
}
}
}
Any help would be greatly appreciated.
Thanks.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |