regex - DataAnnotations RegularExpression fails -


I have a visual model with property in which regular expression data annotation:

  Public class CreateProductViewModel {[Regular expression ("[A-Za-z0-9]")]] Public string name {get; Set; }}  

Regular expression should only validate alphanumeric characters.

However, in an attempt to save the value "abc", verification fails.

I have tried to change the regular expression in "[^ A-Za-z0- 9]" , but it also fails.

What am I doing wrong?

Add * or + after the expression, because now it will show that the string is valid only when it is a letter To have this work you have two options:

  [Regular expression ("[A-Za-z0-9] +")]  

or string.


Comments