用户名校验
验证用户名,4
到 16
位,允许 字母
,数字
,下划线
,减号
。
语法
import { usernameReg } from 'warbler-js';
const result = usernameReg(value);
参数
value
(String) : 待验证字符串。
返回值
Boolean : 是否通过验证,true
通过验证, false
没有通过验证。
源码
const usernameReg = (value) => {
const reg = /^[a-zA-Z0-9_-]{4,16}$/;
return reg.test(value);
};
例子
import { usernameReg } from 'warbler-js';
const result1 = usernameReg('warbler_js01')
console.log(result1) // true