/*
 * @Author: Gui
 * @Date: 2023-04-07 16:09:33
 * @LastEditors: guicheng 1625811865@qq.com
 * @LastEditTime: 2024-06-21 10:44:32
 * @Description: tel files
 * @filePath:
 */

export function RegularVerification(zz: any, value: any, callback: any) {
  const reg = zz;
  if (!reg.test(value)) {
    callback(new Error('请输入正确格式'))
  }
}

const verification = {
  //姓名
  verificationName: (value: any, callback: any) => {
    const reg = /^(?:[\u4e00-\u9fa5·]{2,16})$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入姓名'))
    }
  },
  //银行卡号
  verificationBankCard: (value: any, callback: any) => {
    const reg = /^[1-9]\d{9,29}$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确的银行卡号'))
    }
  },
  //手机号码
  verificationPhonenNmber: (value: any, callback: any) => {
    const reg = /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\d{8}$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确手机号码'))
    }
  },
  //6位短信验证码
  verificationPhoneCode: (value: any, callback: any) => {
    const reg = /^\d+$/;
    if ((!reg.test(value) || value.length !== 6) && value) {
      callback(new Error('请输入正确短信验证码'))
    }
  },
  //邮箱
  verificationEmail: (value: any, callback: any) => {
    const reg = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确邮箱'))
    }
  },
  //社会统一信用代码
  verificationCreditCode: (value: any, callback: any) => {
    const reg = /^(([0-9A-Za-z]{15})|([0-9A-Za-z]{18})|([0-9A-Za-z]{20}))$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确社会统一信用代码'))
    }
  },
  //身份证号码
  verificationIdCardNumber: (value: any, callback: any) => {
    const reg = /^[1-9]\d{5}(?:18|19|20)\d{2}(?:0[1-9]|10|11|12)(?:0[1-9]|[1-2]\d|30|31)\d{3}[\dXx]$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确身份证号码'))
    }
  },
  //链接地址
  verificationUrl: (value: any, callback: any) => {
    const reg = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入正确链接地址'))
    }
  },
  //整数
  verificationInteger: (value: any, callback: any) => {
    const reg = /^(?:0|(?:-?[1-9]\d*))$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入整数'))
    }
  },
  //浮点数
  verificationFloat: (value: any, callback: any) => {
    const reg = /^(-?[1-9]\d*\.\d+|-?0\.\d*[1-9]\d*|0\.0+)$/;
    if (!reg.test(value) && value) {
      callback(new Error('请输入浮点数'))
    }
  },
}

export default verification
