Chikwado Posted March 7, 2015 Share Posted March 7, 2015 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 More sharing options...
Don E Posted March 7, 2015 Share Posted March 7, 2015 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 More sharing options...
Chikwado Posted March 8, 2015 Author Share Posted March 8, 2015 Yes, This your example works very fine. Thank you. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now