正则匹配
用于对输入的字符串进行正则匹配。
matchNumber
匹配一个字符串是否是纯数字。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
ts
import { matchNumber } from 'liv-web';
console.log(matchNumber('123')); // true
console.log(matchNumber('abc')); // falsematchPassword
匹配一个字符串是否是密码。(至少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%')); // falsematchPhone
匹配一个字符串是否是手机号。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
ts
import { matchPhone } from 'liv-web';
console.log(matchPhone('15888888888')); // true
console.log(matchPhone('12345678910')); // falsematchIdCard
匹配一个字符串是否是身份证。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
ts
import { matchIdCard } from 'liv-web';
console.log(matchIdCard('360121199503253035')); // true
console.log(matchIdCard('36011119950325')); // falsematchLongitude
匹配一个字符串是否是经度。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
ts
import { matchLongitude } from 'liv-web';
console.log(matchLongitude('180')); // true
console.log(matchLongitude('-180.0')); // true
console.log(matchLongitude('180.1')); // falsematchLatitude
匹配一个字符串是否是纬度。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
ts
import { matchLatitude } from 'liv-web';
console.log(matchLatitude('90')); // true
console.log(matchLatitude('-90.0')); // true
console.log(matchLatitude('90.111')); // falsematchEmail
匹配一个字符串是否是邮箱。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| 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')); // falsematchDecimal
匹配一个字符串是否是小数。
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| string | 需要匹配的字符串 | string | — |
| options | 匹配参数 | MatchDecimalOptions | — |
MatchDecimalOptions
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| min | 最小值 | number | -Infinity |
| max | 最大值 | number | Infinity |
| minDigits | 最小位数 | number | 0 |
| maxDigits | 最大位数 | number | Infinity |
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