Validating email form javascript

This was really a lengthy process which used to put a lot of burden on the server.

Java Script provides a way to validate form's data on the client's computer before sending it to the web server. First let us see how to do a basic form validation.

Validating email is a very important point while validating an HTML form. You can modify or rewrite the said regular expression.

In this page we have discussed how to validate an email using Java Script : An email is a string (a subset of ASCII characters) separated into two parts by @ symbol.

Form validation normally used to occur at the server, after the client had entered all the necessary data and then pressed the Submit button.

If the data entered by a client was incorrect or was simply missing, the server would have to send all the data back to the client and request that the form be resubmitted with correct information.

In the above form, we are calling validate() to validate data when onsubmit event is occurring.

The following code shows the implementation of this validate() function.

It is important to validate the form submitted by the user because it can have inappropriate values. The Java Script provides you the facility the validate the form on the client side so processing will be fast than server-side validation.So, most of the web developers prefer Java Script form validation.Through Java Script, we can validate name, password, email, date, mobile number etc fields.The regex for validating the correct email format in line 2 has been borrowed and edited slightly by adding the i flag so that the regex is case-insensitive.The if block in lines 3-6 checks to see if the email address in the first field passes the regex check by invoking the search() method on our email string value.The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.

You must have an account to comment. Please register or login here!