0

I am having an issue using the RegularExpressionValidator using Visual Studio 2010. This is my code:

<asp:Label ID="phone" runat="server" Text="Phone Number"></asp:Label><asp:TextBox ID="phonebox"
    runat="server" TextMode="Phone"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" 
    ErrorMessage="Invalid Number" ControlToValidate="phonebox" 
    ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>
<br />

No matter what number I type in, I get an error message beside the field - even if I copy and paste a valid US phone number.

AnonJr
  • 2,759
  • 1
  • 26
  • 39
Javacadabra
  • 5,578
  • 15
  • 84
  • 152

1 Answers1

0

Refer to this link: http://www.w3schools.com/aspnet/prop_webcontrol_textbox_textmode.asp

Despite that enumeration on msdn you should use only this three:
SingleLine - Default. One line text box
MultiLine - Text box with multiple lines
Password - One line text box that masks the input

I suggest to leave it as simple text (default value) and use one of RegEx to verify correctness

<asp:TextBox ID="phonebox" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" 
ErrorMessage="Invalid Number" ControlToValidate="phonebox"     ValidationExpression="((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}"></asp:RegularExpressionValidator>

Few others RegEx you can find at: Regular expression to validate US phone numbers?

Community
  • 1
  • 1
Hide
  • 115
  • 2
  • 11