Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular Expression allow only numbers, commas and dashes

I'm trying to come up with a Data Annotation regular expression to match the following formats.

34

38-30

100,25-30

4-5,5,1-5

Basically the expression should only allow numbers, -(dash) and ,(comma) in any order

I tried following but couldn't get it working.

[RegularExpression(@"(0-9 .&'-,]+)", ErrorMessage ="Lot numbers are invalid.")]
like image 593
chamara Avatar asked Aug 12 '26 05:08

chamara


1 Answers

It's ^[0-9,-]*$. Check out this demo.

like image 178
Anis Alibegić Avatar answered Aug 15 '26 09:08

Anis Alibegić



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!