senzacionale
senzacionale

Reputation: 20906

MVC 3.0 decimal number validation on model

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?

Upvotes: 1

Views: 2758

Answers (2)

Glory Raj
Glory Raj

Reputation: 17691

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

^\d*\.?\d+$

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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.

Upvotes: 3

Related Questions