// 验证金额
export function validateMoneyNumber(rule, value, callback) {
  var reg = /^([1-9][\d]{0,10}|0)(\.[\d]{1,2})?$/

  if (!reg.test(value)) {
    callback(new Error(rule.message))
  } else {
    callback()
  }
}

// 验证手机号码
export function isValidateMobile(value) {
  var reg = /^((\+86)|(86))?[1][0-9]{10}$/

  if (value == '') {
    return true
  }
  return reg.test(value)
}

// 验证电话号码号码
export function isValidatePhones(rule, value, callback) {
  var reg = /^((\+86)|(86))((([0+]d{2,3}-)?(0d{2,3})-)(d{7,8})(-(d{3,}))?)|([1][0-9]{10})?$/

  // console.log(rule, value, callback);
  if (!reg.test(value)) {
    callback(new Error(rule.message))
  } else {
    callback()
  }
}

// 验证URL
export function isUrl(rule, value, callback) {
  // eslint-disable-next-line no-useless-escape
  var reg = /^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;%\$#_]*)?/

  if (!reg.test(value)) {
    callback(new Error(rule.message))
  } else {
    callback()
  }
}

// 验证Email
export function isEmail(rule, value, callback) {
  var reg = /^[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/

  if (!reg.test(value)) {
    callback(new Error(rule.message))
  } else {
    callback()
  }
}

// 验证身份证号码
export function isIdCard(rule, value, callback) {
  var reg = /^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/

  if (!reg.test(value)) {
    callback(new Error(rule.message))
  } else {
    callback()
  }
}
