const validator = {
  hasNum(value: string) {
    return new RegExp('[0-9]+').test(value);
  },
  hasLowerEnChar(value: string) {
    return new RegExp('[a-z]+').test(value);
  },
  hasUpperEnChar(value: string) {
    return new RegExp('[A-Z]+').test(value);
  },
  hasSpecialChar(value: string) {
    return new RegExp('[~!@#$%^&*()_+|<>,.?/:;\'\\[\\]{}"]+').test(value);
  },
  isRange(value: string, min: number, max: number) {
    return new RegExp(`^.{${min},${max}}$`).test(value);
  },
  isPass(value: string) {
    if (!this.isRange(value, 8, 18)) return false;
    if (!this.hasNum(value)) return false;
    if (!this.hasLowerEnChar(value)) return false;
    if (!this.hasUpperEnChar(value)) return false;
    if (!this.hasSpecialChar(value)) return false;
    return true;
  },
};

export default validator;
