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

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

Edited 6 Years Ago by Duki: n/a

Comments
Dude, no fair, I can't stop giggling now!!
Made me laugh!

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

This question has already been answered. Start a new discussion instead.