How do you tell if the content of a string is numeric?

I can only think of
let a;
a = which may be letters, numbers, Chinese characters, symbols, etc.;
if (Number.isFinite (a-0) = true) {
/ / then this an is a finite number, but cannot judge an infinite number.
}
is there any other way that is more reasonable

Sep.16,2021

isNaN () should be able to meet the needs of the subject, the method means to check whether the parameter is a non-number.

when the variable to be checked is of type string, this method returns false only if the string is composed of pure numbers, and true in other cases.

The mechanism of

this method is that the parameters are internally typed. When a string is encountered when converting a numeric type, it will stop and return NaN, so only a string composed of pure numbers will be successfully converted to a number.
in addition, if it is the 'Infinity' of a string, it can be converted to the infinitesimal and infinitesimal of the corresponding numeric type, so no special processing is required.


var reg=/^\d+$/ig
if(reg.test(str)){
console.log('');
}else{
console.log('');
}

if you take into account the decimal, use the following:

var reg=/ ^\ d + (.\ d +)? $/ ig


so this an is a finite number, but it cannot be judged that an infinite number
does infinity mean 1 big 0
else if(a==='Infinity'){
  console.log('')
}

didn't understand the topic, it was hilarious

Menu