Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Data annotations Regular expression

I need regular expression validation for first 5 digits are numbers then hyphen and then one digit is alphabet and other one is numeric.

ex : 23456-p5 or 12345-a3 something like that.

I have tried something like this to start with

/^\d{5}-\d{2}$/ 

and in model i have given like this as we don't have to give ^ or $ in data annotations

[RegularExpression(@"d{5}-\d{2}")] 

But i couldnt get it to work even this.

like image 412
veena panakanapalli Avatar asked Sep 08 '25 03:09

veena panakanapalli


1 Answers

Try this:

[RegularExpression(@"^\d{5}-[a-zA-Z]\d$")]
like image 192
Bidou Avatar answered Sep 09 '25 22:09

Bidou