-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* email address | ||
*/ | ||
export const RegEx_Email = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/ | ||
|
||
/** | ||
* domain name | ||
*/ | ||
export const RegEx_Domain = /[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+\.?/ | ||
|
||
/** | ||
* (weak) password: 6~18 bits, contain: `letters` / `numbers` / `_` | ||
* and must start with letters | ||
*/ | ||
export const RegEx_Password = /^[a-zA-Z]\w{5,17}$/ | ||
|
||
/** | ||
* strong password: 8~16 bits, contain: `letters` and `numbers` | ||
* Special characters cannot be used | ||
* 必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-16之间 | ||
*/ | ||
export const RegEx_StrongPassword = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/ | ||
|
||
/** | ||
* phone number | ||
*/ | ||
export const RegEx_PhoneNumber = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { | ||
RegEx_Domain, | ||
RegEx_Email, | ||
RegEx_Password, | ||
RegEx_PhoneNumber, | ||
RegEx_StrongPassword | ||
} from './constants' | ||
|
||
/** | ||
* Check val is domain name | ||
* @param val the check val | ||
* @returns boolean | ||
*/ | ||
export const isDomainName = (val: string): boolean => RegEx_Domain.test(val) | ||
/** | ||
* Check val is email | ||
* @param val the check val | ||
* @returns boolean | ||
*/ | ||
export const isEmail = (val: string): boolean => RegEx_Email.test(val) | ||
|
||
/** | ||
* Check val is phone number | ||
* @param val the check val | ||
* @returns boolean | ||
*/ | ||
export const isPhoneNumber = (val: string): boolean => RegEx_PhoneNumber.test(val) | ||
|
||
export { | ||
RegEx_Domain, | ||
RegEx_Email, | ||
RegEx_Password, | ||
RegEx_PhoneNumber, | ||
RegEx_StrongPassword | ||
} |