hello
i think this code will help. U have to change the code a little bit
according to ur situation. in my case if the phone no. is valid then it will
return true. u can send return the validated phone no or error message.
Note: in this function i have use a string variavble ErrorMessage which is
member of the class. You have to handle it urself.
for any more help you can contact me via emal --->
cu*****@hotmail.com
public bool Validity( string PhoneNo)
{
bool flag = false;
if( PhoneNo[0] >= '0' && PhoneNo[0] <= '9' || (PhoneNo[0] == '+') )
{
for(int i = 1; i < PhoneNo.Length; i++)
{
if( (PhoneNo[i] >= '0' && PhoneNo[i] <= '9') || (PhoneNo[i] == '_') ||
(PhoneNo[i] == '-') || (PhoneNo[i] == ' ') )
flag = true;
else
{
this.ErrorMessage = "The character \"" + email[i] + "\" is not allowed
in the PhoneNo";
flag = false;
break;
}
}
}
else
{
this.ErrorMessage = "First character must be between 0-9 or it may be + ";
flag = false;
}
return flag;
}
"Joe" wrote:
Hi,
I am stuggling with building a regular expression that would allow only 0-9,
+, -,_, space, (, ). Can someone guide me. This is for validating phone using
JavaScript in my asp page.
Thanks for you time,
Joe