Help with regular expression

G

Guest

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
 
G

Guest

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 ---> (e-mail address removed)

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 >= '0' && PhoneNo <= '9') || (PhoneNo == '_') ||
(PhoneNo == '-') || (PhoneNo == ' ') )
flag = true;
else
{
this.ErrorMessage = "The character \"" + email + "\" 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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top