There is such a piece of code: the result of if (RegExp.test(num)) is TRUE every time in IE, but in Fire Fox, if it is True the first time, it must be False the second time, and appears alternately thereafter. Take a look at the past solutions:
Method 1: Change if (RegExp.test(num)) to if (num.match(RegExp))
Method 2: Use RegExp object processing, that is, new RegExp("^(-)?[0-9]*$").
I don’t know if it has been verified. Anyway, I have tried it but it can’t achieve the compatibility effect. In fact, the last The fundamental problem is not which regular object to use, but the "g" in the expression causes the effect in Firefox to be inconsistent with IE. Firefox treats the RegExp as a global variable, so the simplest and most effective way is to use var RegExp =/^(-)?[0-9]*$/g Change to var RegExp=/^(-)?[0-9]*$/, a good solution does not care about complexity, but the right solution, so After all, the situation is not common.
function isNum(num){
if(num.length==0){
return false;
}
var RegExp=/^(-)?[0-9]*$/g;
if (RegExp.test(num)){
return true;
}else{
return false;
}
}