Click here to Skip to main content
15,567,466 members
Please Sign up or sign in to vote.
4.50/5 (4 votes)

I have a model named Scheme in my MVC Project. in that model i have a field "Period". that is a decimal value. i want to validate this field like, the value after the deciml point should be in the range (1,13).

how can i do that

please help me

You don't state this clearly, but it seems that you are treating this "decimal" value more like a version number, in the format [number].[number]. I know you already gave yourself credit for the correct answer, but I have to disagree.

First of all, your regex [\d]{1,}\.[\d][0-3]{1} has some extraneous syntax. Here's the clean equivalent: \d+\.\d[0-3]

It will incorrectly match these values:
1.00, 1.20, 1.21, 1.22, 1.73, 1.90, ...
It will incorrectly miss these values:
1.1, 1.2, 1.3, ...

This is what you really want:
Share this answer
Kunjammu 26-Aug-14 6:47am    
it is not allowing integers. i want a regular expression which allows positive integers and decimal numbers having two decimal points whose values ranges from 0-13
i got the solution

[RegularExpression(@"[\d]{1,}\.[\d][0-3]{1}", ErrorMessage = "Number after decimal point should not greater than 12")]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900