This is an answer to question mentioned in the topic, not the actual one in the body of the text :).
The following method is more accurate on determining if the string is a real integer.
function isInteger(possibleInteger) {
return /^[d]+$/.test(possibleInteger)?;
}
Your current method validates "7.5" for instance.
EDIT: Based on machineghost's comment, I fixed the function to correctly handle arrays. The new function is as follows:
function isInteger(possibleInteger) {
return Object.prototype.toString.call(possibleInteger) !== "[object Array]" && /^[d]+$/.test(possibleInteger);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…