954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

tel no validation

Hey the code I have for validating the tel no is not working for the string value (567) 789-5677

String rePhoneNumber = @"\([1-9]\d{3}\)\s?\d{3}\-\d{4}$";
            Regex re = new Regex(rePhoneNumber);

            if (re.IsMatch(textBox1.Text))
                MessageBox.Show("valid phone number");
            else
                MessageBox.Show("Phone Number Must Be Entered As: (555) 555-1234");


Every time the else part is being executed
Why is this can somebody explain the code??
thanxxx

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

I just tried calling, and the phone number isn't working anyways so no worries! :)

Duki
Nearly a Posting Virtuoso
1,475 posts since Jun 2006
Reputation Points: 817
Solved Threads: 32
 

use regx think you will do this with this

hirenpatel53
Posting Whiz in Training
221 posts since Jun 2010
Reputation Points: 10
Solved Threads: 27
 

Your regex string is looking for 4 digits inside the ().
One for [1-9] and then another 3 digits with \d{3}.
Change \d{3} to \d{2} and it should work.

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 
Your regex string is looking for 4 digits inside the (). One for [1-9] and then another 3 digits with \d{3}. Change \d{3} to \d{2} and it should work.


hey thaxxxxxx

judithSampathwa
Posting Pro in Training
453 posts since May 2010
Reputation Points: 8
Solved Threads: 0
 

Hey, Your welcome.
Hey, maybe these links will help for future Regex projects.
CodeProject - The 30 Minute Regex Tutorial
MSDN - Regular Expression Language Elements
RegExLib.com - Telephone Numbers
Hey, if resolved, please mark solved.;)

nick.crane
Nearly a Posting Virtuoso
1,230 posts since Feb 2010
Reputation Points: 375
Solved Threads: 187
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: