Jump to content

JavaSrcipt Validate Phone Number


Chikwado

Recommended Posts

Some one check this how to validate phone number with javascript. I have the following code but not so sure.

<!DOCTYPE html>
<html>
<head>
<script>
function myfunction() {
var x=document.forms
["myForm"]["phone"].value;
if (x==isNaN(0-9) || x==isNaN(0-9);
{ alert("Input your phone number");
return false;
}
}
</script>
</head>
<body>
<form name="myForm"
action="demo_form.asp"
onsubmit="return validateForm()"
method="post">
Phone number:<input type="text" name="phone">
<input type="submit" value="Submit">
</form>
</body>
</html>
I don't know the outcome of this code but I am try to validate phone number with it. Some one help.
Link to comment
Share on other sites

You mean something like this?

<!doctype html><html><head><meta charset="UTF-8"><title>phone</title><script type="text/javascript">function validateForm() {    var x = document.forms["myForm"]["phone"].value;    if(isNaN(x))    {        alert("Input your phone number");      return false;    }}</script></head><body>    <form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">    Phone number:<input type="text" name="phone">    <input type="submit" value="Submit">    </form></body></html>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...