/*
 * @Author: 吴永生#A02208 yongsheng.wu@wholion.com
 * @Date: 2022-06-13 17:23:49
 * @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
 * @LastEditTime: 2022-06-13 17:28:59
 * @FilePath: /bkunyun/src/utils/helper.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
const getTrueLength = (str: string) => {//获取字符串的真实长度（字节长度）
  let len = str.length, truelen = 0;
  for (let x = 0; x < len; x++) {
    if (str.charCodeAt(x) > 128) {
      truelen += 2;
    } else {
      truelen += 1;
    }
  }
  return truelen;
}

export const verifyLettersNumbersCertainChars4 = (str: string) => {
    if (str.slice(0, 1) === ".") {
        return false;
    }
    if (getTrueLength(str) > 127) {
        return false;
    }
    let validString = /^[\u4e00-\u9fa5_0-9a-zA-Z-_.]+$/;
    return validString.test(str);
};

export const verifyLettersNumbersCertainChars5 = (str: string) => {
    if (str.slice(0, 1) === ".") {
      return false;
    }
    if (getTrueLength(str) > 127) {
      return false;
    }
    let validString = /^[\u4e00-\u9fa5_0-9a-zA-Z/-_.]+$/;
    return validString.test(str);
  };