JavaScript Validations - Javascript Advanced

What is JavaScript Form Validations?

Form validation commonly used to occur at the server, after the client had entered data in all the necessary fields and then clicked the Submit button. If the data entered by a client consists of incorrect data or was simply missed entering the data, the server would have to send back all the data to the client and request that the form to be resubmitted with correct data. This process was really lengthy which will put a lot of burden on the server.

You can use JavaScript in order to validate form's data on the client's computer before checking it with the web server. Form validation basically performs two functions.
  • Basic Validation − Basic validation mainly focusses on checking of whether all the mandatory fields are filled in. This can be done by placing a loop through each field in the formfor checking the data.
  • Data Format Validation – Data Format validation is done to make sure that the data entered in all the fields is having correct form and value. Your code must include suitable logic to test for correctness of data.
We will take below example to for better understanding the process of validation. Here we can see a simple form in html format.

JavaScript Validations Output

What is Basic Form Validation?

First let’s see how to perform a basic form validation. In the above form, we are calling validate() function in order to validate data when onsubmit event occurs. The below code explains the implementation of this validate() function.

What is Data Format Validation?

Let us see how we can validate theentered data in the form before submitting it to the web server.

The following example explains how to validate an entered email address.
An email address must contain ‘@’ sign and a dot (.). Also, the ‘@’ must not be the starting character of the email address, and the last dot must least be one character after the ‘@’ sign.
Try the below code which explains how to validate email email address.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

Javascript Advanced Topics