Posts Tagged ‘floating point’

Test if the given value is a decimal number or not in JavaScript using Regular Expression

26 May

To identify in JavaScript whether the number or a string is in a decimal format or not, is actually pretty easy and short.
It looks obvious, but actually it doesn’t due to several different combinations of decimal number representation in JavaScript.

I’m using Regular Expression to test it:

function isDecimal(number) {
    return /^\d+(\.\d+|e)(e?-\d+)?$/.test(number);

Read the rest of this entry »