var reg = /^\d+|(-[1-9])$/;for (i = -10; i <= 10; i++) { console.log(i + ': ', reg.test(i))}
测试结果
-10: false-9: true-8: true-7: true-6: true-5: true-4: true-3: true-2: true-1: true0: true1: true2: true3: true4: true5: true6: true7: true8: true9: true10: true[Finished in 0.3s]