Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Phone Number Validation

Status
Not open for further replies.

apw420

MIS
May 12, 2004
6
US
Can't figure out how to validate a phone number. Such as: Number has to be in (123) 456-7890 format.

Have this code to validate data is entered:
Code:
<script type = "text/javascript">



function validate()
		{
		 		
				if (theform.name.value=="")
				{
				 	 alert('Your name is required!');
					 return false;
				}
				
								if (theform.phone.value=="")
				{
				 	 alert('How can we call you without a phone number!!');
					 return false;
				}
				
								if (theform.email.value=="")
				{
				 	 alert('Your email is required!');
					 return false;
				}
}
</script>

Any idea how to validate the phone number structure (and e-mail as well!!!) for this form:
Code:
			<form name= "theform" onsubmit="return validate();" method="post" action="[URL unfurl="true"]http://matrix.csis.com/~s04-it604-s13/cgi-bin/insertEst.pl">[/URL]

			Your Name<br>
			<input type="text" name="name" size=30>
			<p>
			Email Address<br>
			<input type="text" name="email" size=30>
			<p>
			Your Phone Number<br>
			<input type="text" name="phone" size=15>
Thank you!
AW
 
If you're in the US, you can do a fairly easy validation - just make sure that the length is no mare than 10 and that there are no alpha characters. If you expect to get any phione numbers from outside the US, don't bother trying to do anything other than testing that the field is empty. I maintain a web site for a client who deals strictly overseas and believe me, there is nothing standard about international phone numbers.

There's always a better way. The fun is trying to find it!
 

>> If you expect to get any phione numbers from outside the US, don't bother trying to do anything other than testing that the field is empty.

How very, very xenophobic.

 

>> If you expect to get any phione numbers from outside the US, don't bother trying to do anything other than testing that the field is empty. I maintain a web site for a client who deals strictly overseas and believe me, there is nothing standard about international phone numbers.

How very, very xenophobic. Each country has their own standards - it's just a case of finding them out for each country.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top