jeffmace
asked on
Best way to validate Phone Number and Email???
Can someone please post some code examples(javascript) that show how to validate a phone number. I only want digits(example: 1231231234 NOT 123-123-1234). If you know of a way to allow international numbers as well that would be great (example this is a phone number from Europe: Phone: +44 20 8390 xxxx). I am not sure if there is a way to show that it is a USA number or a foreign number, but if it is possible that would be great.
Also what is the best way to check that a person typed in a valid email address(Example. test@aol.com NOT test@aol or whatever).
Thanks
Also what is the best way to check that a person typed in a valid email address(Example. test@aol.com NOT test@aol or whatever).
Thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
take a look at this from another thread
<html>
<head>
<script language="javascript">
function validate(emailad) {
a = emailad.split(";")
var exclude=/[^@\-\.\w]|^[_@\. \-]|[\._\- ]{2}|[@\.] {2}|(@)[^@ ]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$ /;
for(i=0;i<a.length;i++)
{
emailadd = a[i];
if(((emailad.search(exclud e) != -1)||(emailad.search(check )) == -1)||(emailad.search(check end)
== -1)){
alert("Incorrect email address!");
return false
}
else {
alert('hello')
//document.form.submit();
}
}
}
</script>
</head>
<body>
<form method="post" action="this.htm">
<input type="text" name="email" onBlur="javascript:validat e(this.val ue)";>
<input type="submit">
</form>
</body>
<html>
<head>
<script language="javascript">
function validate(emailad) {
a = emailad.split(";")
var exclude=/[^@\-\.\w]|^[_@\.
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$
for(i=0;i<a.length;i++)
{
emailadd = a[i];
if(((emailad.search(exclud
== -1)){
alert("Incorrect email address!");
return false
}
else {
alert('hello')
//document.form.submit();
}
}
}
</script>
</head>
<body>
<form method="post" action="this.htm">
<input type="text" name="email" onBlur="javascript:validat
<input type="submit">
</form>
</body>
this can be the best possible
http://cflib.org/udf.cfm?ID=216
Example
<cfoutput>
#YesNoFormat(IsEmail("jgui llaume@sto neage.com" ))#<br>
#YesNoFormat(IsEmail("jgui llaume@sto neage.com. info"))#<b r>
#YesNoFormat(IsEmail("jgui llaume@sub domain.sto neage.muse um"))#<br>
#YesNoFormat(IsEmail("jgui llaume@sto neage.inva lidTLD"))#
</cfoutput>
Output
Yes
Yes
Yes
No
Hope that helps
K'Rgds
Anand
http://cflib.org/udf.cfm?ID=216
Example
<cfoutput>
#YesNoFormat(IsEmail("jgui
#YesNoFormat(IsEmail("jgui
#YesNoFormat(IsEmail("jgui
#YesNoFormat(IsEmail("jgui
</cfoutput>
Output
Yes
Yes
Yes
No
Hope that helps
K'Rgds
Anand
I use this Netscape RegEx written library:
http://developer.netscape.com/docs/examples/javascript/regexp/overview.html
It is really good, it has simple methods for everything. US Number, SSN, International Number, Email Address, Dates, Zip Codes, Credit Cards, and it even has text box validation and has easy ways to warn the user with a message.
CJ
http://developer.netscape.com/docs/examples/javascript/regexp/overview.html
It is really good, it has simple methods for everything. US Number, SSN, International Number, Email Address, Dates, Zip Codes, Credit Cards, and it even has text box validation and has easy ways to warn the user with a message.
CJ
ne-luck ???
function isEmail (v) {
var email = /^[a-zA-Z0-9._-]+@([a-zA-Z
if(!email.test(v)) {
alert('Wrong')
}
}