baozhengrui

导航

校验

/**
 * 邮箱
 * @param {*} s
 */
export function isEmail (s) {
  return /^([a-zA-Z0-9._-])+@([a-zA-Z0-9_-])+((.[a-zA-Z0-9_-]{2,3}){1,2})$/.test(s)
}
export const pattern = {
  // 正数
  isPositive: /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,4})?$/,
  // 万元用的正则
  isMoney: /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,4})?$/,
  // 正整数
  isNatural: /^(0|[1-9][0-9]{0,9})?$/,
  // 小数
  isDecimal: /^(0|[1-9][0-9]{0,9})(\.[0-9]{1,6})?$/,
  //四位小数
  fourDoubleDecimal: /^(0|[1-9][0-9]*)(\.[0-9]{1,4})?$/,
  // 百分比格式带两位小数
  percentage: /^(([1-9]{1}([0-9]{1})?)|[0]|[1]{1}[0]{2}|[1-9]\d{1,2})((\.[0-9]{1}([0-9]{1})?)?)$/,
  // 负数校验经费
  fuMoney:/^(\-|\+)?\d{1,9}(\.\d{1,4})?$/
}
/**
 * 手机号码
 * @param {*} s
 */
export function isMobile (s) {
  return /^1[0-9]{10}$/.test(s)
}

/**
 * 电话号码
 * @param {*} s
 */
export function isPhone (s) {
  return /^([0-9]{3,4}-)?[0-9]{7,8}$/.test(s)
}

/**
 * URL地址
 * @param {*} s
 */
export function isURL (s) {
  return /^http[s]?:\/\/.*/.test(s)
}

posted on 2024-09-10 10:15  芮艺  阅读(2)  评论(0编辑  收藏  举报