JavaScript Number Validation (Decimal)
Decimals can be validated in JavaScript using a regular expression:
document.write(/^-?\d+(\.\d+)?$/.test('15.22'));
Broken down into sections:
^-?\d+ - The string being tested must begin with an optional minus sign, followed by 1 or more digits
(\.\d+)? - Followed by an optional period, which, if present must be followed by 1 or more digits.
Related Articles:
JavaScript Regular Expressions
JavaScript Regular Expression Special Characters: $ ^
JavaScript Number Validation (Integer)
JavaScript Regular Expression Plus Sign
July 12, 2007 at 1:40 pm
Good one
thanks a Lot
September 7, 2007 at 2:51 am
Finaly some simplicity…thanks a lot…
June 20, 2009 at 3:33 am
Helpful.
Thanks