Search within TutorialsPark

Javascript Forms: Validation


Validate form inputs before sending it to the server using JavaScript


Javascript Forms: Validation

JavasScript can be used to perform some preliminary tests on the form inputs, before sending the data to server.

This takes care of erroneous information saving time for both users and the server, and since the script is executed on the client side there is no excess load on the server.

The preliminary checks can be performed to check for password length, empty field, unwanted text etc.

Some validations require use of Regular Expressions for pattern matching for addresses, zip codes, phone numbers etc. We learn more about it in further chapters.


Javascript Form: Check Empty Form Fields

Some form fields are mandatory and require an input from the user before the form is submitted

The below demo uses JavaScript to check for such empty input fields.

Example: JavaScript Form Validation Checking for Empty form Fields

Give it a TRY! » Note: The form will not be submitted until a text is supplied in the form filed.


Javascript forms : Check for Alphabets

The Demo below uses JavaScript to check for alphabets used as input within username, address etc. A loop checks each character in a string to ensure its an alphabetic.

Example: Javascript Forms Validation: Check Alphabet Characters.

Give it a TRY! » Note: The function ensures that only alphabetic charcters(not case sensitive) are validated.


Javascript Form Validation : Validate E-Mail Address

The demo below uses JavaScript to perform a basic check to see the existence of both @ symbol and . symbol in the input for Email Address.

Example: Javascript Forms textarea Object

Give it a TRY! » Note: It checks just for a basic symbol of @ and ..


Javascript Form Validation: Password Pattern Check

The below demo uses JavaScript codes to create a simple validation routine which checks for a alphanumeric character of size atleast eight(8).

Example: Javascript Form Validation: Password check

Give it a TRY! » Note:Enter a value for password less than 8 characters to see the effects.