Try this sample code, i think it helps you: <head> <script> function CheckAndSubmit () { var userName = document.getElementById ("userName"); if (userName.value.length < 3) { alert ("The name of the user must be at least 3 characters long!"); return false; } var password = document.getElementById ("password"); var repassword = document.getElementById ("repassword"); if (password.value.length < 6) { alert ("The password must be at least 6 characters long!"); return false; } if (repassword.value != password.value) { alert ("The two passwords are different!"); return false; } var acceptAgreement = document.getElementById ("acceptAgreement"); if (!acceptAgreement.checked) { alert ("You must accept the User Agreement to register!"); return false; } return true; } </script> </head> <body> <form id="regForm" method="post" action="#URL#" onsubmit="return CheckAndSubmit ()"> User Name: <input type="text" name="userName" id="userName" /> <br /> Password: <input type="password" name="password" id="password" /> <br /> Repeat Password: <input type="password" name="repassword" id="repassword" /> <br /><br /> <input type="checkbox" name="acceptAgreement" id="acceptAgreement" /> <label for="acceptAgreement">I accept the User Agreement and Privacy Policy</label> <br /><br /> <input type="submit" value="Register" /> </form> </body> Code (markup):
Which type of validation do you want? There are so many validation in form fields like Name, Date, Mail, URL, Pincode, Telephone number, Do not blank.. If you really want to do then read Javascript Expression language...