Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1-First n number of digits only then a hyphen last n number of alphanumeric values
2-contains only one hyphen no other special characters
eg : 123-abc - right pattern
123456-abcdgdt - right pattern
-adadad - wrong pattern
123--adad - wrong pattern
-123-adad - wrong pattern
abcd-123-ada - wrong pattern
Posted

1 solution

^[0-9]+[-]{1}[a-zA-Z]+$

^ start of the string
[0-9]+ accept only numbers 1 or more
[-]{1} take exactly one dash
[a-zA-Z]+ accept only letters 1 or more
$ end of the string
 
Share this answer
 
Comments
harikrishnanmb 26-Sep-14 2:22am    
Thank you so much

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