同时含有数字和英文字母

验证字符串,必须同时含有 数字英文字母

语法

  1. import { nlBothReg } from 'warbler-js';
  2. const result = nlBothReg(value);

参数

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

返回值

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

源码

  1. const nlBothReg = (value) => {
  2. const reg = /^(?=.*[a-zA-Z])(?=.*\d).+$/;
  3. return reg.test(value);
  4. };

例子

  1. import { nlBothReg } from 'warbler-js';
  2. const result1 = nlBothReg('1')
  3. const result2 = nlBothReg('aa')
  4. const result3 = nlBothReg('3aa')
  5. console.log(result1) // false
  6. console.log(result2) // false
  7. console.log(result3) // true