// 用户名正则, 4到16位 (字母, 数字, 下划线, 减号)
const uPattern = /^[a-zA-Z0-9_-]{4,16}$/;
// 密码强度正则, 最少6位, 包括至少1个大写字母, 1个小写字母, 1个数字, 1个特殊字符
const pPattern = /^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@#$%^&*? ]).*$/;
// 自然数正则
const posPattern = /^\d+$/;
// 负整数正则
const negPattern = /^-\d+$/;
// 整数正则
const intPattern = /^-?\d+$/;
// 正数正则 整数也可以是浮点数
const posPattern = /^\d*\.?\d+$/;
// 负数正则 整数也可以是浮点数
const negPattern = /^-\d*\.?\d+$/;
// 数字正则 整数也可以是浮点数
const numPattern = /^-?\d*\.?\d+$/;
// Email正则 [async-validator](https://github.com/yiminghe/async-validator/blob/master/src/rule/type.ts)
const ePattern = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+\.)+[a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{2,}))$/;
// 手机号正则
const mPattern = /^1[34578]\d{9}$/;
//身份证号 (18位)正则
const cP = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
// URL正则
const urlP= /^((https?|ftp|file):\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
// ipv4地址正则
const ipP = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/;
// RGB Hex颜色正则
const cPattern = /^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$/;
// 日期正则, 简单判定,未做月份及日期的判定
const dP1 = /^\d{4}(\-)\d{1,2}\1\d{1,2}$/;
// 日期正则, 复杂判定
const dP2 = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
// QQ号正则, 5至11位
const qqPattern = /^[1-9][0-9]{4,10}$/;
// 微信号正则, 6至20位, 以字母开头, 字母, 数字, 减号, 下划线
const wxPattern = /^[a-zA-Z]([-_a-zA-Z0-9]{5,19})+$/;
// 车牌号正则
const cPattern = /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/;
// 包含中文正则
const cnPattern = /[\u4E00-\u9FA5]/;
// 中文标点符号
const cnMark = /[\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5]/
// 金额数字格式千分位
(12345678890.123).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,');
// const number = 12345678890.123;
// new Intl.NumberFormat().format(number)
// function formatMoney(num){
// return (+num).toLocaleString("en-US");
// }
// 如需处理更长的小数位数 请在本站搜索"数字格式化千分位"
// 去除字符串中的html代码
const removeHTML = (str = '') => str.replace(/<[\/\!]*[^<>]*>/ig, '')
console.log(removeHTML('<h1>哈哈哈哈<呵呵呵</h1>')) // 哈哈哈哈<呵呵呵
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70