kisAccount method

bool kisAccount({
  1. AccountRegex regex = AccountRegex.def,
  2. int min = 6,
  3. dynamic max = 18,
})

是否匹配用户名 min 最小位数,max最长位数

Implementation

bool kisAccount(
    {AccountRegex regex = AccountRegex.def, int min = 6, max = 18}) {
  String regexStr;
  switch (regex) {
    case AccountRegex.def:
      regexStr = "^[0-9A-Za-z\\W]{6,18}\$";
      break;
    case AccountRegex.charNumNoSpecial:
      regexStr = "^(?![0-9]+\$)(?![a-zA-Z]+\$)[0-9A-Za-z]{6,18}\$";
      break;
    case AccountRegex.charOrNumOrSpecial2:
      regexStr = "^(?![0-9]+\$)(?![a-zA-Z]+\$)[0-9A-Za-z\\W]{6,18}\$";
      break;
    case AccountRegex.charNumSpecial:
      regexStr =
          "^(?![0-9]+\$)(?![a-zA-Z]+\$)(?![0-9a-zA-Z]+\$)(?![0-9\\W]+\$)(?![a-zA-Z\\W]+\$)[0-9A-Za-z\\W]{6,18}\$";
      break;
    default:
      regexStr = "^[0-9A-Za-z\\W]{6,20}(?<!_)\$";
      break;
  }
  regexStr = regexStr.replaceAll("6", "$min").replaceAll("18", "$max");
  return matches(regexStr);
}