Skip to content
大纲

用户名校验 ​

验证用户名,4 到 16 位,允许 字母,数字,下划线,减号。

语法 ​

js
import { usernameReg } from 'warbler-js';
const result = usernameReg(value);

参数 ​

  • value (String) : 待验证字符串。

返回值 ​

Boolean : 是否通过验证,true 通过验证, false 没有通过验证。

源码 ​

js
const usernameReg = (value) => {
  const reg = /^[a-zA-Z0-9_-]{4,16}$/;
  return reg.test(value);
};

例子 ​

js
import { usernameReg } from 'warbler-js';
const result1 = usernameReg('warbler_js01');

console.log(result1); // true

添加版本 ​

1.2.0

Released under the MIT License.