Reputation: 2218
I am wondering for Regular Expression that accepts only letters,numbers and dashes.
I will add it on my viewmodel class.I am working on asp.net-mvc-4 application.And using MVC Data Annotations.
I want to validate one string field there.With that regex.
Upvotes: 4
Views: 3375
Reputation: 6728
If you pay attention to the above screen shot. Above is a passed case and below one is failed case.
Upvotes: 2
Reputation: 10667
Regex that matches only letters, numbers, and dashes:
^[0-9a-zA-Z-]*$
Recommend you try the gskinner regex tool, it is very helpful.
Upvotes: 1
Reputation: 1073
you can use this
/[a-zA-Z\d-]+/
this will validate all the alphabets, numbers and dashes.
Upvotes: 0