Validating data javascript

For the majority of your users, Java Script form validation will save a lot of time up front, but double-checking the data on the server remains necessary, in case the user has turned Java Script off.

Form data that typically are checked by a Java Script could be: validate Form On Submit ( ) This is a main function that calls a series of subfunctions, each of which checks a single form element for compliance.

Any interactive web site has form input - a place where the users input different kind of information.

This data is passed to ASP script, or some other technology and if the data contains an error, there will be a delay before the information travels over the Internet to the server, is examined on the server, and then returns to the user along with an error message.

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.

We want to allow only letters, numbers and underscopes.

validating data javascript-49validating data javascript-14validating data javascript-1

You can use a client-side scripting solution like Java Script that performs certain validation rules before submitting the form data.

validate Email ( ) Next we want to see if the email address the user entered is real.

This means that the input data must contain at least an @ sign and a dot (.).

So we should use a new regular expression to forbid underscopes. Next, we want to permit only passwords that contain letters and at least one numeral.

For that we use the seacrh() method and two more regular expressions: /(a-z) / and /(0-9)/.

Leave a Reply