@tmsfe/tms-core 0.0.210 → 0.0.211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.210",
3
+ "version": "0.0.211",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/index.js CHANGED
@@ -55,6 +55,13 @@ import { getMpOpenId, getOuterOpenId, getEncryptUserInfo } from './mpInfo';
55
55
  import * as storage from './storage';
56
56
  import * as uiUtil from './tmsuiUtils';
57
57
  import { throttle, debounce } from './funcUtils';
58
+ import {
59
+ validTaxId,
60
+ validPhone,
61
+ validName,
62
+ validEmail,
63
+ validIdNumber,
64
+ } from './regCheck';
58
65
  import { formatAmount } from './priceUtils';
59
66
  import { getSystemInfoSync } from './wxApi';
60
67
 
@@ -242,6 +249,13 @@ const api = {
242
249
  /* 金额方法 */
243
250
  formatAmount,
244
251
 
252
+ /* 常见正则校验 */
253
+ validTaxId,
254
+ validPhone,
255
+ validName,
256
+ validEmail,
257
+ validIdNumber,
258
+
245
259
  /* 时间方法 */
246
260
  groupTimeDuration,
247
261
  formatTimeDuration,
@@ -0,0 +1,40 @@
1
+ /**
2
+ * 常见正则校验
3
+ */
4
+
5
+ // 校验税号
6
+ function validTaxId(taxId) {
7
+ return /^[A-Z0-9]{15}$|^[A-Z0-9]{17}$|^[A-Z0-9]{18}$|^[A-Z0-9]{20}$/.test(taxId);
8
+ }
9
+
10
+ // 校验电话、手机号
11
+ function validPhone(phone) {
12
+ const reg = /^(1[3456789]\d{9}|(\d{3,4}-\d{7,8}))$/;
13
+ return reg.test(phone);
14
+ }
15
+
16
+ // 校验姓名只允许中英文
17
+ function validName(name) {
18
+ const reg = /^[\u4e00-\u9fa5a-zA-Z]+$/;
19
+ return reg.test(name);
20
+ }
21
+
22
+ // 验证邮箱地址
23
+ function validEmail(email) {
24
+ const regExp = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
25
+ return regExp.test(email);
26
+ }
27
+
28
+ // 匹配身份证号
29
+ function validIdNumber(idNumber: string): boolean {
30
+ const regExp = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
31
+ return regExp.test(idNumber);
32
+ }
33
+
34
+ export {
35
+ validTaxId,
36
+ validPhone,
37
+ validName,
38
+ validEmail,
39
+ validIdNumber,
40
+ };