For Asp.Net mvc model validation I'm trying to create a regex for the following requirement:
- string length between 1-5 (including 1 and 5 limit)
- non word characters are not allowed
- underscore not allowed
I can write a regex witch matches the non word characters but not the inverse of my question.
Regex
Non word characters and underscore match:
([\W_])
String length between 1 and 5:
{1-5}
Asp.net mvc Code:
namespace x
{
public class Model
{
[RegularExpression(@"")]
public string AString {get;set;}
}
}