0% found this document useful (0 votes)
23 views2 pages

JavaScript Form Validation Guide

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)
23 views2 pages

JavaScript Form Validation Guide

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

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="[Link]" 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=[Link];

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

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

return false;

var num=[Link];

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

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

return false;

if (isNaN(num)){

[Link]("numloc").innerHTML="Enter Numeric value only";

return false;

}else{

return true;
}

var x=[Link];

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

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

return false;

var atposition=[Link]("@");

var dotposition=[Link](".");

if (atposition<1 || dotposition<atposition+2 || dotposition+2>=[Link]){

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


dotposition:"+dotposition);

return false;

</script>

</body>

</html>

You might also like