负整数(不包含0)
验证 负整数。
语法
import { negativeIntegerReg } from 'warbler-js';
const result = negativeIntegerReg(value);
参数
value
(String) : 待验证字符串。
返回值
Boolean : 是否通过验证,true
通过验证, false
没有通过验证。
源码
const negativeIntegerReg = (value) => {
const reg = /^-[1-9]\d*$/;
return reg.test(value);
};
例子
import { negativeIntegerReg } from 'warbler-js';
const result1 = negativeIntegerReg('0')
const result2 = negativeIntegerReg('-3')
const result3 = negativeIntegerReg('4')
const result4 = negativeIntegerReg('1.1')
const result5 = negativeIntegerReg('一尾流莺')
console.log(result1) // false
console.log(result2) // true
console.log(result3) // false
console.log(result4) // false
console.log(result5) // false