JS Form validation

FORM VALIDATION

JavaScript provides a way to validate form’s data on the client’s computer before sending it to the web server. Form validation generally performs two functions.

  • Basic Validation− First of all, the form must be checked to make sure all the mandatory fields are filled in. It would require just a loop through each field in the form and check for data.
  • Data Format Validation− Secondly, the data that is entered must be checked for correct form and value. Your code must include appropriate logic to test correctness of data.

 


 

Validation

  1. All mandatory fields are filled
  2. User name
    1. Mandatory
    2. Minimum Length
  3. Password check
    1. Mandatory
    2. Minimum Password length
    3. Include alphabets in lower and upper case, digits and special characters
    4. Retyped password is same
  4. Email
    1. Must contain the @ and . character
    2. Must have at least one character before and after the @
    3. Must be at least two characters after . (dot)
  5. Mobile number
    1. Check digits only
    2. Length of mobile number
  1. Checkbox (can use ‘required’ or function)
    1. Atleast one choice selected
    2. Accept terms and conditions
  2. File
    1. Extension
    2. Max size

Example Program for HTML and Form Validation