Organizational Research By

Surprising Reserch Topic

mvc 4 dataannotations validation for type using -'asp.net,asp.net-mvc,data-annotations'


mvc 4 dataannotations validation for type  using -'asp.net,asp.net-mvc,data-annotations'

I have the following code working

    [Required(ErrorMessage = "Price is required.")]
    [Range(typeof(Decimal), "1", "9999", ErrorMessage = "Price xx.xx")]
    public decimal? productPrice { get; set; }


When the page is submitted with
Price = EMPTY Field error message is "Price is required.".
Price = over 9999 error message is "Price xx.xx".

However, when I type 'aaaa' the error message is
"The field productPrice must be a number."

How can I change the message if type in not correct?
Like : "Price must be a decimal/number between 1-9999.

---- UPDATE: ----
The below code worked with

NULL, Not Decimal, Between Range, BUT not working with ".1".

    [Required(ErrorMessage = "Price is required.")]
    [RegularExpression(@"[0-9]*\.?[0-9]+", ErrorMessage = "Price must be a Numbers only.")]
    [Range(typeof(Decimal), "1", "9999", ErrorMessage = "Price must be a decimal/number between {1} and {2}.")]
    public decimal? productPrice { get; set; }

    
asked Sep 7, 2015 by rajesh
0 votes
9 views



Related Hot Questions



Government Jobs Opening


...