Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends

i trying on Regular Expression for formatting Which accept numbers and only one special character please help me?

Example:

32-54
or
655-654

like this



Thanku
Posted
Updated 22-Dec-14 22:10pm
v2
Comments
Maciej Los 23-Dec-14 4:14am    
What have you tried?
murkalkiran 23-Dec-14 4:17am    
i have tried for only numbers but not getting any idea to use special characters
Use regex ^(0|[1-9]\d*)$ for required pattern

Try:
^\d+[-_~]\d+$
Which accepts hyphen, underscore, and tilde as the "special characters" - change that for the ones you need to accept
 
Share this answer
 
^\d\-\d$

\d is for digits (numbers)
\- is for - (hyphen)
 
Share this answer
 
I think you can get the information you need here: Regular Expressions info[^]

When it comes to characters that are defined with a special meaning, you need to escape them with a backslash (\).

Example:
[0-9\-]+
or
[0-9]+\-[0-9]+


Remember to escape once more if you your language require that.
 
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