2

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

Community
  • 1
  • 1

2 Answers2

0

You can use the regex

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

see the regex101 demo

marvel308
  • 10,288
  • 1
  • 21
  • 32
0

Try this one: ^\d+((?=[\,\.])([\.\,]\d+|$))*$.

Nick Kugaevsky
  • 2,935
  • 1
  • 18
  • 22