Hitori Hitori - 2 years ago 62
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.

Answer Source

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/>');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download