1

In DB i have decimal type like decimal(10, 2)

Can i validate input filed on MVC 3.0 model if is decimal like for URL: [Url] ,...

http://weblogs.asp.net/imranbaloch/archive/2011/02/05/new-validation-attributes-in-asp-net-mvc-3-future.aspx

Does anything like this already exist or i must write custom validator?

2 Answers 2

3

Decimal fields are automatically validated by the default model binder. You don't need to do anything special. If you try to assign an invalid value to a decimal field on your view model you will get a validation error.

Sign up to request clarification or add additional context in comments.

4 Comments

Thx. What about the length. 10,3 ?
@senzacionale, what about it?
i want that no one can write value larger than 10,3
@senzacionale, ah, you would use the [Range(min, max)] attribute. Take a look here: stackoverflow.com/questions/7256753/…
2

I hope it will helps you.... create a custom validator that uses Decimal.TryParse under the covers.

^\d*\.?\d+$

1 Comment

Don't use regexes for these things. They'll break badly with localization.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.