-
Regular Expressions
I want to create Regular Expression for phone number and valid digits allowed are (,),-,+,0----9. If the left bracket ( is there,then its necessay that right bracket is also there. How to create the Regular Expression for the above. I dont know how to create the regular Expression,they just kill me.
-
Re: Regular Expressions
hay,
this will return true,
Code:
string phoneNumber = "444-6666";
bool val = System.Text.RegularExpressions.Regex.IsMatch(phoneNumber, "^[0-9,()+-]{8,12}$");
if you just write the formula that you want for the phone i think i can help
-
Re: Regular Expressions
Hey,
Check the link in my signature, there are a number of Regex related links in it.
Specifically, Regex Lib, it has a own library of Regular Expressions, so it is likely that you will find the one that you need there.
You might also want to check this out:
http://gskinner.com/RegExr/
A very helpful online regular expression checker.
Hope that helps!
Gary
-
Re: Regular Expressions
HI avrail, I want the following validations to apply -
(0124) - 900000
(91) + 78777
If I use ur code and write (1234) - 7878 in textbox I am getting false. I want that if the number is in the format as above,it will return true.. and one thing more I have to limit the numbers entered are just 10 exclusing () + -
-
Re: Regular Expressions
hay mansi,
sorry i wasn't here
Code:
string phoneNumber = "(0123) - 123456";
bool val = System.Text.RegularExpressions.Regex.IsMatch(phoneNumber
, @"^(\(\d{2}\)\s?[-|+]\s?\d{5,6}|\(\d{4}\)\s?[-|+]\s?\d{5,6})$");