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

Recommended Answers

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

Jump to Post

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.

Jump to Post

All 5 Replies

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

commented: Made me laugh! +1
commented: Dude, no fair, I can't stop giggling now!! +1

use regx think you will do this with this

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.