嘿,我只需要一个标准的JS验证,以允许字符串只有正或负的#,没有小数。
1 = true
10 = true
-10 = true
-1.5 = false
1.5 = false谢谢
发布于 2014-10-16 22:20:27
这里使用正则表达式:
function isInteger(n) {
return (typeof n == 'number' && /^[-]?[0-9]+$/.test(n+''));
}这个也适用于字符串:
function isInteger(n) {
return /^[-]?[0-9]+$/.test(n+'');
}这是基于How to check if a variable is an integer in JavaScript?的macloving的回答
Fiddle
https://stackoverflow.com/questions/26406259
复制相似问题