Newer
Older
KaiFengPC / src / views / preassess / targetManage / validate.js
@zhangdeliang zhangdeliang on 23 May 849 bytes 初始化项目
const message = {
  area: '面积不能为空',
  annualRunoffTotalControlRate: '年径流总量控制率不能为空',
  annualRunoffPollutionControlRate: '年径流污染控制率不能为空',
  hardGroundRate: '硬质地面率不能为空',
}
export const validate = (rule, value, callback) => {
  if (value === '') {
    callback(new Error(message[rule.field] || ''))
  } else {
    const reg = /^\d+(\.\d+)?$/
    if(reg.test(value)) callback()
    else callback(new Error('请输入数字'))
  }
}

export const validatePhone = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('电话不能为空'))
  } else {
    const phoneReg = /^[1][3456789][0-9]{9}$/
    const dhReg = /0\d{2,3}-\d{7,8}/
    if(phoneReg.test(value) || dhReg.test(value)) callback()
    else callback(new Error('请输入正确的电话'))
  }
}