const validator = {
  mobile(rule: any, value: any, callback: any) {
    if (!/^1\d{10}$/.test(value)) {
      callback(new Error('请输入正确的手机号'))
    }
    callback()
  },
  email(rule: any, value: any, callback: any) {
    if (!/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.([a-zA-Z]{2,4})$/.test(value)) {
      callback(new Error('请输入正确的邮箱'))
    }
    callback()
  },
  idCard(rule: any, value: any, callback: any) {
    if (!/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$/.test(value)) {
      callback(new Error('请输入正确的身份证号码'))
    }
    callback()
  }
}

export default validator
