You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
/**
* 邮箱校验函数
* @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 ) ; // 使用正则表达式校验邮箱格式
}
/**
* 手机号码校验函数
* @param {*} s 输入的字符串
*/
export function isMobile ( s ) { // 定义手机号码校验函数
return /^1[0-9]{10}$/ . test ( s ) ; // 使用正则表达式校验手机号码格式, 以1开头的11位数字
}
/**
* 电话号码校验函数
* @param {*} s 输入的字符串
*/
export function isPhone ( s ) { // 定义电话号码校验函数
return /^([0-9]{3,4}-)?[0-9]{7,8}$/ . test ( s ) ; // 使用正则表达式校验电话号码格式, 可带区号( 3-4位) , 号码长度为7-8位
}
/**
* URL地址校验函数
* @param {*} s 输入的字符串
*/
export function isURL ( s ) { // 定义URL地址校验函数
return /^http[s]?:\/\/.*/ . test ( s ) ; // 使用正则表达式校验URL格式, 支持http和https协议
}
/**
* 匹配数字,可以是小数,不可以是负数,可以为空
* @param {*} s 输入的字符串
*/
export function isNumber ( s ) { // 定义数字校验函数
return /(^-?[+-]?([0-9]*\.?[0-9]+|[0-9]+\.?[0-9]*)([eE][+-]?[0-9]+)?$)|(^$)/ . test ( s ) ; // 使用正则表达式校验数字格式,支持小数、科学计数法,允许为空
}
/**
* 匹配整数,可以为空
* @param {*} s 输入的字符串
*/
export function isIntNumer ( s ) { // 定义整数校验函数
return /(^-?\d+$)|(^$)/ . test ( s ) ; // 使用正则表达式校验整数格式,允许负数,允许为空
}
/**
* 身份证校验函数
*/
export function checkIdCard ( idcard ) { // 定义身份证校验函数
const regIdCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/ ; // 定义身份证号码的正则表达式, 支持15位、18位, 最后一位可以是数字或X/x
if ( ! regIdCard . test ( idcard ) ) { // 如果身份证号码不符合正则表达式
return false ; // 返回false, 表示校验失败
} else {
return true ; // 返回true, 表示校验成功
}
}