Kendo TextBoxFor allow only numbers in .NET

1

I do not want to allow the user to enter characters in my TextBoxFor field, and if he does, I want to display a message stating that the field should contain only numbers.

My code is below.

@(Html.Kendo().TextBoxFor(model => model.MinVoltage).Name("MinVoltage").HtmlAttributes(new { style = "width: 6em;font-size:12px;font-weight:normal" }))
@Html.ValidationMessageFor(model => model.MinVoltage)

My C # class looks like this:

    [Column("MAX_VOLTAGE")]
    [Required(ErrorMessage = "Campo obrigatório")]
    [Display(ResourceType = typeof(Messages), Name = "MaximumVoltage")]
    [RegularExpression("([1-9][0-9]*)", ErrorMessage = "Somente valores numéricos")]
    [Range(0.1, 99.99, ErrorMessage = "Valores válidos: 0.1 a 99.99 ")]
    public double MaxVoltage { get; set; }

This is not working

What would be the best way to do this?

    
asked by anonymous 11.07.2017 / 15:14

1 answer

2

Set type = "number" to TextBoxFor

@(Html.Kendo().TextBoxFor(model => model.MinVoltage).Name("MinVoltage").HtmlAttributes(new { type = "number", style = "width: 6em;font-size:12px;font-weight:normal" }))
    
11.07.2017 / 19:04