What is the correct way to check if a string is valid number in javascript?
Normally we use isNaN(str)
, this works great in all cases but excepts,
Current behaviour:
isNaN("1") = false, is a number,
isNaN("1 ") = false, But this is a string.
What is the correct approach to deal with this?
Expected results:
isNotNumber("1") = false
isNotNumber("1 ") = true