Validation in ES6

Facebooktwitterredditpinterestlinkedinmailby feather

Validation in ES6

The term validation can be defined as a mechanism to check the information given by the user is correct or not according to the requirements. If the data provided by the front-end user is incorrect or undefined, the web server sends it back to the user. The server also requests to resubmit the form that contains the correct information.

The validation process is done at the web server end. The server sends the validation to the client. It is a time taken to process for both users as well as for the web server. ES6 provides a facility to the user to validate the data form before sending it to the web server.

There are following two functions of form validation. They are-

Basic Validation: It is a process of checking that all the essential fields are filled or not.

Data Format Validation: It helps us to make sure that the input data is correct or not. The data form validation process involves a convenient logic for data testing.

syntax

The above syntax contains the following parameters.

action=“page redirection”: It is used to redirect the current page to next page if the input information is correct.

Onsubmit= “return function()”: When the user clicks on the submit button, then this parameter invokes the validate function.

Name=“form name”: The name parameter helps us to access the value from the form.

Here, we will try to elaborate on each validation in detail.

Basic Form Validation

This type of form validation is used to check all essential input fields whether filled or not.

Here, we have an example to understand the above validation.

Example

Output

After the successful execution of the above example, we got the following output:

Validation in ES6

If we click on the submit button without entering the data in text fields, it will show the following alert message.

Validation in ES6

Data Format Validation

In the data format validation, we have to check that the input data having correct value or not. It validates the already filled input fields to check if the provided information is correct or not.

Here, we have an example to understand the above validation.

Example

Output

After the execution of the above example, we got the following output:

Validation in ES6

If we click on the submit button without entering the data, then we will get the following alert message.

Validation in ES6
Facebooktwitterredditpinterestlinkedinmailby feather