Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Need Regular Expression which include and allow below conditions.

-max. number of characters: 25 characters
-min. number of characters: 10 characters
-only allow numbers not alphabetic chars.[0-9]
-allow spaces, parentheses, plus and minus sign

i need regex which allow this type of format
Posted
Updated 2-May-14 18:55pm
v2
Comments
Sampath Lokuge 28-Apr-14 8:51am    
Check this one.May be helped to you. http://www.regexlib.com/Search.aspx?k=phone

Google gave me sites like http://regexlib.com/[^], browse there

OR

Create yourself. Check these
Expresso - A Tool for Building and Testing Regular Expressions[^]
The 30 Minute Regex Tutorial[^]
 
Share this answer
 
For you question this regex will do:
^[0-9\+\- \(\)]{10,25}$

But! To check phone number it definitely not good, as it allows the plus sign to appear anywhere, allows unclosed parentheses...
So if you want to check phone numbers you may split it to two. One for a regex to check that no invalid char are in the input, and one other to check syntax...
 
Share this answer
 
v2
^[+]\d{2}\s[(]\d{3}[)]\s[\d]{5}-[\d]{5}$
 
Share this answer
 
 
Share this answer
 
check following
^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$
^(\+91[\-\s]?)\d{10}$
 
Share this answer
 
v2
you can use ajax

C#
<asp:toolkitscriptmanager id="ToolkitScriptManager1" runat="server" >
    </asp:toolkitscriptmanager>

 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:FilteredTextBoxExtender ID="FilteredTextBoxExtender1" runat="server" TargetControlID="TextBox1" FilterMode="ValidChars" FilterType="Custom" ValidChars="+()-0123456789">
    </asp:FilteredTextBoxExtender>


FilteredTextBox
 
Share this answer
 
v2

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