Saturday, 14 November 2015

JavaScript Form Validation



Without Validation of the Form we Can not get the Actual Data From User

Which we want for our Application Form or Account. User May Enter String

Value in the Place of the integer Value or may Enter a wrong User name or

password. so It is necessary to Validate a Form. Here , is the Simple 


Example To Validate a Form Using a JavaScript.

Form Constraints:

Here , I Put Some of the Constraints to Validate a Form. Like

Login Name : it Contains alphabets, number , .(dot), _ (underscore)

Password : Password Length is 6 to 15

Comments : Optional

Age : Must be integer

Email-Id : Valid Email-ID

Contact No. : 10 digits Contact number ( no need to give the area or

country code)

validate Email-Id

To Validate a Email-id is the Important point while Validate a Form. so here ,

We will discuss how to validate a email-ID.

Email-ID Constraints

In The below HTML Program, I Supposed a Some Email-ID

Constraints Which are given under the Following points:

1. Email-ID Should not be Start with . (dot or Comma).

2. it Should Contains a Valid domain name (Like .com, .co.in, .net, .org etc)

3. Digits (0-9)

4. Alphabets (upper case and lower case)

Example of the Validate Email-ID

abc@xyz.com

deepak@gmail.com

abc.xy@num.co.net

javaScript function

Here, is the JavaScript Function To Validate the Email-Id






function ValidEmail()

{
var emailid=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
var email=document.getElementById("emailid").value;
if(!emailid.test(email))
alert("Enter correct email-id");
else
alert("Your Email-ID is Correct");
}


Source Code

formValidation.html File

HTML Source Code to Design a Application Form.


form.js File


JavaScript Code To Validate the Application Form, Whether User Enter

a Correct data types According our Requirement or not.



DOWNLOAD FREE SOURCE CODE HERE

Now, 
Step-1. You Copy The formValidation.html file, Paste in Notepad or

Other Id's and Save it as .html FIle.

Step-2. Similarly, You Copy The form.js file, Paste in Notepad or

Other Id's and Save it as .html FIle in the same folder where you save

your .html file.

Step-3. Now, Open the formValidation.html file in any Web browser

and Check The Application Form.

Thank You To All My Reader

Aman Kapoor
www.CodeMon5ter.blogspot.in

No comments:

Post a Comment