Cycymomo
7/4/2013 - 4:38 PM

isNumber javascript

isNumber javascript

function isNumber(n) {
  n = n.toString().replace(/,/g, '.'); // en chaine, puis convertir , en .  
  return !isNaN(parseFloat(n)) && isFinite(n);
}
 
console.log(isNumber(5)); // true
console.log(isNumber(4597)); // true
console.log(isNumber("lol")); // false
console.log(isNumber("9.489.")); // false
console.log(isNumber("9.489")); // true
console.log(isNumber("4579,312")); // true
console.log(isNumber("4,579,312")); // false
console.log(isNumber("5,2")); // true
console.log(isNumber("8e3")); // true
console.log(isNumber(",5")); // true
console.log(isNumber(".5")); // true