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 [...]
Filed under: Internet, JavaScript, Programming, Software, Web | 2 Comments »