Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2629
  • Last Modified:

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!
0
JaimeJegonia
Asked:
JaimeJegonia
1 Solution
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now