0% found this document useful (0 votes)
59 views

Validation Using Javascript

The document contains code to validate a registration form in JavaScript. It uses regular expressions to validate an email address, phone number, and name. The validation checks that the email contains @ and . in the correct positions, the phone number only contains numeric values, and the name is not empty. If any validation fails, an alert is shown.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Validation Using Javascript

The document contains code to validate a registration form in JavaScript. It uses regular expressions to validate an email address, phone number, and name. The validation checks that the email contains @ and . in the correct positions, the phone number only contains numeric values, and the name is not empty. If any validation fails, an alert is shown.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Validate e-mail, phone no, name using regular expression in JavaScript.

<!DOCTYPE html>

<html>

<head>

<title>

</title>

</head>

<body>

<form name="myform" method="post" action="abc.jsp" onsubmit="return validateform()" >

Name: <input type="text" name="name"><br/>

Number: <input type="text" name="num"><span id="numloc"></span><br/>

Email: <input type="text" name="email"><br/>

<input type="submit" value="register">

</form>

<script>

function validateform(){

var name=document.myform.name.value;

if (name==null || name==""){

alert("Name can't be blank");

return false;

var num=document.myform.num.value;

if (num==null || num==""){

alert("Number can't be blank");

return false;

if (isNaN(num)){

document.getElementById("numloc").innerHTML="Enter Numeric value only";

return false;

}else{

return true;
}

var x=document.myform.email.value;

if (x==null || x==""){

alert("Email can't be blank");

return false;

var atposition=x.indexOf("@");

var dotposition=x.lastIndexOf(".");

if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){

alert("Please enter a valid e-mail address \n atpostion:"+atposition+"\n


dotposition:"+dotposition);

return false;

</script>

</body>

</html>

You might also like