Kendo Textboxfor allow only numbers in . NET

Asked

Viewed 431 times

1

I don’t want to allow the user to enter characters in my field Textboxfor, and if so, I want to display a message 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 class C# is 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 that?

1 answer

2


Put the type = "number" in the TextBoxFor

@(Html.Kendo().TextBoxFor(model => model.MinVoltage).Name("MinVoltage").HtmlAttributes(new { type = "number", style = "width: 6em;font-size:12px;font-weight:normal" }))
  • Thank you very much, that’s exactly it

Browser other questions tagged

You are not signed in. Login or sign up in order to post.