Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to validate india landline numbers.
maximum length of indian landline number is 11.
it will starts with std code after that 6-8 digits.
like this.

044-444444
044-44444444
04175-22222

but it wont exceeds 11

i have given validation like this

"^[0-9]\d{2,4}-\d{6,8}$" 


the above regular expression is accepting more than 11 digits..
in the above regex i need to give maximum length.

how to do that?
Posted

Solution:
Check this Link Phone number validation

Let me know if still found it hard.
 
Share this answer
 
you can use

XML
<asp:TextBox ID="tbTelephoneNo" runat="server"></asp:TextBox>
       <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="tbTelephoneNo" ValidationExpression="^\d{5,8}$" ErrorMessage="Error"></asp:RegularExpressionValidator>
 
Share this answer
 
You can try this regex using lookahead. Lookahead doesn't consume any characters from the input, it just does a check.

First the length including '-' is checked. In this case I set it to max 12 characters.
If the length is ok, then the next expression is tested otherwise it fails.
^(?(?=^[\d\-]{0,12}$)[0-9]\d{2,4}-\d{6,8})$


I hope it helps.

Have a look here for more info.

If-Then-Else Conditionals in Regular Expressions[^]
 
Share this answer
 
v3
Try this
[0-9]{3}[-][0-9]{6,8}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900