Skip to content

正则匹配

用于对输入的字符串进行正则匹配。

matchNumber

匹配一个字符串是否是纯数字。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchNumber } from 'liv-web';

console.log(matchNumber('123')); // true
console.log(matchNumber('abc')); // false

matchPassword

匹配一个字符串是否是密码。(至少8位,至多20位,至少包含1个大写字母、1个小写字母、1个数字和1个特殊字符)

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchPassword } from 'liv-web';

console.log(matchPassword('Admin@123456%')); // true
console.log(matchPassword('admin@123456%')); // false

matchPhone

匹配一个字符串是否是手机号。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchPhone } from 'liv-web';

console.log(matchPhone('15888888888')); // true
console.log(matchPhone('12345678910')); // false

matchIdCard

匹配一个字符串是否是身份证。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchIdCard } from 'liv-web';

console.log(matchIdCard('360121199503253035')); // true
console.log(matchIdCard('36011119950325')); // false

matchLongitude

匹配一个字符串是否是经度。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchLongitude } from 'liv-web';

console.log(matchLongitude('180')); // true
console.log(matchLongitude('-180.0')); // true
console.log(matchLongitude('180.1')); // false

matchLatitude

匹配一个字符串是否是纬度。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchLatitude } from 'liv-web';

console.log(matchLatitude('90')); // true
console.log(matchLatitude('-90.0')); // true
console.log(matchLatitude('90.111')); // false

matchEmail

匹配一个字符串是否是邮箱。

参数说明类型默认值
string需要匹配的字符串string
ts
import { matchEmail } from 'liv-web';

console.log(matchEmail('0123456789@163.com')); // true
console.log(matchEmail('0123456789@163')); // false
console.log(matchEmail('0123456789@com')); // false

matchDecimal

匹配一个字符串是否是小数。

参数说明类型默认值
string需要匹配的字符串string
options匹配参数MatchDecimalOptions

MatchDecimalOptions

参数说明类型默认值
min最小值number-Infinity
max最大值numberInfinity
minDigits最小位数number0
maxDigits最大位数numberInfinity
ts
import { matchDecimal } from 'liv-web';

console.log(matchDecimal('10')); // false
console.log(matchDecimal('10.5')); // true
console.log(matchDecimal('15', { min: 10, max: 30 })); // true
console.log(matchDecimal('15.123', { maxDigits: 2 })); // false
console.log(matchDecimal('40.12', { min: 10, max: 30, maxDigits: 2 })); // false