0

I need to validate phone number that allows numeric and symbols + - () how can i do so in asp.net?

<asp:TextBox ID="TxtNo" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Enter valid Phone number" ControlToValidate="TxtNo" ></asp:RegularExpressionValidator>
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
user2240189
  • 315
  • 3
  • 7
  • 20
  • Do you mean US phone numbers only? In my opinion use an input mask to force data entry in a specific manner rather than trying to figure out what the user entered. – Candide Sep 03 '13 at 06:45

3 Answers3

2

you need to add

<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Enter valid Phone number" ControlToValidate="TxtNo" ValidationExpression="^[01]?[- .]?(\([2-9]\d{2}\)|[2-9]\d{2})[- .]?\d{3}[- .]?\d{4}$" ></asp:RegularExpressionValidator> 

with the expression that should specify the format that needs to be validated. You can choose one from here and specify it in the validation expression above

Ehsan
  • 31,833
  • 6
  • 56
  • 65
1
ValidationExpression= "^([0-9\(\)\/\+ \-]*)$"

<asp:TextBox ID="TxtNo" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" 
runat="server" ErrorMessage="Enter valid Phone number" 
ControlToValidate="TxtNo" 
ValidationExpression= "^([0-9\(\)\/\+ \-]*)$"></asp:RegularExpressionValidator>
Haidar Abbas
  • 192
  • 4
1

Try this validation expression

^([\(]{1}[0-9]{3}[\)]{1}[\.| |\-]{0,1}|^[0-9]{3}[\.|\-| ]?)?[0-9]{3}(\.|\-| )?[0-9]{4}$
Arun Bertil
  • 4,598
  • 4
  • 33
  • 59