Validating a form using java script

Rated 3.87/5 based on 731 customer reviews

Otherwise it returns a message describing the error and highlight appropriate element with yellow.

validate Empty ( ) The function below checks if a required field has been left empty.

Live demo: Longmuir/pen/Wb Oydx data-validate is injected in all the input fields of your form but when using js Form Validator, you don't require this heavy syntax and the validation will be applied to your form in one shot, without need to touch at your HTML code.

The CGI script is still more reliable, as it always works regardless of whether Java Script is enabled on the client-side or not; but having this extra safety barrier is a nice thing to have in place.

If the required field is blank, we return the error string to the main function.

If its not blank, the function returns an empty string.

validate Username ( ) The function below checks if the user entered anything at all in the username field.

If its not blank, we check the length of the string and permit only usernames that are between 5 and 15 characters.

Leave a Reply