To validate a phone number take a html form
the html code should be
<html>
<head>
<title>Your title</title>
</head>
<body>
<form acction="" method="post" onSubmit="return fromvalidation();" >
<imput type="text" id="phno" name="phone_no" placeholder="enter phone number" />
<br />
<input type="submit" name="phone_number_submit" id="ph_sbmt" />
</form>
<script>
function fromvalidation()
{
var phno=document.getElementById('phno').value;
var phno_validation = /^\d{10}$/;
// for 10 digit phone number validation
if(phno.match(phno_validation ))
{
return true;
}
else
{
alert("Not a valid Phone Number");
return false;
}
}
</script>
</body>
</html>
the html code should be
<html>
<head>
<title>Your title</title>
</head>
<body>
<form acction="" method="post" onSubmit="return fromvalidation();" >
<imput type="text" id="phno" name="phone_no" placeholder="enter phone number" />
<br />
<input type="submit" name="phone_number_submit" id="ph_sbmt" />
</form>
<script>
function fromvalidation()
{
var phno=document.getElementById('phno').value;
var phno_validation = /^\d{10}$/;
// for 10 digit phone number validation
if(phno.match(phno_validation ))
{
return true;
}
else
{
alert("Not a valid Phone Number");
return false;
}
}
</script>
</body>
</html>