Client side validation Validation done in the browser before sending the form data to the server using Java Script, j Query and VBScript is called client-side validation. Let us first create the web application with two web pages We are adding two web pages because our requirement is, in the first web page there is form data to be filled in by the user and only after validating the form data, the form will be redirected to the next page.

Server Side Validation Validation done at the server level after sending the form data to the server but before entering the data into the database is called server-side validation. The first page source code Look at the preceding source code closely; see the id's of controls that play the important role in Java Script validation by reading the ASP. The design view of the preceding source code will look as in the following: I hope you have created the same form as above for demonstration purposes. Net controls values in Java Script are as: There are three main methods shown in the above image in the red square to read the ASP.

validating a form using java script-16

var g_Un Focus Element Style = ""; var g_Focus Back Color = "#FFC"; var g_re Email = /^[\w\.=-] \@[\w\.-] .[a-z]$/; var g_re Cell = /^\d$/; var g_invalid Fields = 0; function init Form Elements(s Valid Elems) function highlight Form Element(evt) function un Hightlight Form Element(evt) function validate Address() function validate First Name() function validate Email Address() function validate Cell Phone() function validate Allfields(e) com_abhi.

In this document, we have discussed Java Script Form Validation using a sample registration form.

Now click on the "Create" button; it will redirect to the next page as in the following: Note For detailed code please download the zip file attached above.

Summary From all the examples above we see how to validate the form data using Java Script.

The Java Script class presented here makes the form validations many times easier.

The script has a catalog of almost all the common validation types built-in.Use the following code in the create button: In the code above, only after validating the form data, the page is redirected to the User page. Net web application and click on the Create button without inserting any data in the form, then it will show the following alert message.In the preceding screen you clearly see that even I have wriiten the code on the create button to redirect to the next page but it will not be redirected because the form data is blank and it does not satisfy our validation condition that we set.Net pages, User and User along with the User Java Script file.In the User page the user enters the form details and then only after validating the details the page is redirected to the User page.The user should select an option other than this ‘Select One’ item.