简体   繁体   中英

How to Apply Regex Validation to a textbox in JQuery to enter only decimal(s),integer(s) numbers(if multiple comma seperated)

My HTML Code is

<input type="text" class="form-control textinput" id="Result" name="Result" value="@p.Result"/>

My JQuery Code is :

$(function () {

    $(".textinput").keydown(function (e) {
        var test = ^(\d?\d?\d(,\d\d\d)*|\d+)(\.\d\d)?$;
        var value = String.fromCharCode(e.keyCode);
        if (value.match(test)) {
            return false;
        }
    });
});

I have reffered to This Question but it isn't working,showing an error so please help

My Sample Inputs will be as follows

1,245.30

24,235

135.60,12.6

235.50

34

You can use the regex

^(?:\d+,)*\d+(?:\.\d+)?$

see the regex101 demo

试试这个: ^\\d+((?=[\\,\\.])([\\.\\,]\\d+|$))*$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM