How to validate input text for integers and decimals only?

231 views Asked by At

I cannot find the right answer for my case, so I posted my question here.

I'm validating the form in ASP.NET MVC and looking for the way to validate a text field to allow only numeric and decimal numbers like

1 or 1.5 or 1.65

If I have 1,65 I do not want this to be validated.

I have put a metadata on my Model's field like this: [RegularExpression(@"^(((\d{1})*))$")]

And have

@Html.ValidationMessageFor(m => m.ResolvedAmount, "", new { @class = "error" })

to validate the field.

Also, in my function I have the following to check the validation:

var validator = $("#main").kendoValidator().data('kendoValidator'); 

if(validator.validate()){some logic}

I validate for the required field, but cannot get my int/decimal validation working.

What do I need to have in order to validate it?

0

There are 0 answers