RegularExpressionValidator for Phone Number: (XXX) XXX-XXXX

Hello!

I wanted to validate my textbox in this format: (XXX) XXX-XXXX
This solution doesn't seem to work:

<asp:RegularExpressionValidator id="PhoneValid"
            ControlToValidate="Phone"
            ErrorMessage="Must be in form: (XXX) XXX-XXXX"
            ValidationExpression="(^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)"
            Display="Static"
            Font-Name="Arial" Font-Size="11"
            runat=server>    
</asp:RegularExpressionValidator>

What could be wrong? Can anyone correct it? Thanks!
JaimeJegoniaAsked:
Who is Participating?
 
Ivo StoykovCommented:
Hello JaimeJegonia,

> ValidationExpression="(^x\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)"
try this
ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"

HTH

I
0
 
JaimeJegoniaAuthor Commented:
Wow.. Thanks for the prompt answer! It worked perfect. Thanks again!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.