Explain in brief validating form field using JavaScript ?

Validating Form Fields Using JavaScript in FrontPage

Validating a submitted user is important as it may contain inappropriate values. So the belief is essential.

Javascript provides you the facility that validates the form on the client side, so processing will be faster than server-side validation. Therefore, most web developers prefer JavaScript form validation.

By javascript, we can validate names, passwords, email, date, mobile number etc. fields.

Basic belief - First of all, this form should ensure that all mandatory fields are filled. It will require just one loop through each field in the form and check for the data.

Data Format Validation - Second, the data that is entered should be checked for the correct form and value. To verify the accuracy of the data, your code contains the correct logic.

JavaScript Example

<html> <body> <script> function validateform(){ var name=document.myform.name.value; var password=document.myform.password.value; if (name==null || name==""){ alert("Name can't be blank"); return false; }else if(password.length<6){ alert("Password must be at least 6 characters long."); return false; } } </script> <body> <form name="myform" method="post" action="valid.php" onsubmit="return validateform()" > Name: <input type="text" name="name"><br/> Password: <input type="password" name="password"><br/> <input type="submit" value="register"> </form> </body> </html>