Hitori Hitori - 6 months ago 5x
HTML Question

How can I allow the user to input Numeric (with/without decimal point) only. OR numeric with 'K'/'B'

I've been searching through Stack Overflow, but I can't get the right answer to my question.

How can I allow the user to input a number or number with 'K (Thousands)' or 'M (Millions)'?

I've tried using patterns, RegExp, etc.

Is there a regular expression for this? I tried using

and also
, but I don't know if it is the correct expression.


Think you mean this,

document.write(/^\d+(?:\.\d+)?[KM]?$/.test('121K') + '<br/>');
document.write(/^\d+(?:\.\d+)?[KM]?$/.test('121.7M') + '<br/>');
document.write(/^\d+(?:\.\d+)?[KM]?$/.test('121.45') + '<br/>');