In our actual projects, we often encounter some common regularization methods. Here we will sort them out and update them in the future.(welcome to collect and add)
Common regularization methods
export const regExpConfig = {
Mobile: / ^ 1 ([3 | 4 | 5 | 7 | 8 |] \ D {9} $/, // mobile phone number
Telephone: / ^ (\ (\ D {3,4}) | | D {3,4} - | | s)? D {7,14} /, // fixed line telephone
Num: / ^ [0-9] * $/, // number
Phoneno: / (^ 1 ([3 | 4 | 5 | 7 | 8]) | D {9} $) | (^ (﹤ 3,4} \) | | D {7,14} $) /, // phone or mobile phone
Policeno: / ^ [0-9a-zA-Z] {4,10} $/, // the account consists of 4-10 digits or letters
PWD: / ^ [0-9a-zA-Z] {6,16} $/, // the password consists of 6-16 digits or letters
* / ^ - 9alpha / ^ //
Isalpha: / ^ [a-za-z] * $/, // is it a letter
Isnumalphacn: / ^ [0-9a-zA-Z / u4e00 - \ ufa29] * $/, // whether it is a number or a letter or a Chinese character
Ispostcode: / ^ [\ D -] * $/ I, // is it a postcode
isNumAlphaUline: /^[0-9a-zA-Z_ ]*Are $/, // numbers, letters or underscores
Isnumandthanzero: / ^ ([1-9] - D * (\. [D +))? | 0) $/, // is it an integer and greater than 0 / ^ [1-9] - D * (\. [D +)]$/
Isnormalencode: / ^ (||||[\ u4e00 - \ u9fa5]) {0,} $/, // is it a non special character (including numeric letters, underscores, Chinese characters)
isTableName: /^[a-zA-Z][A-Za-z0-9#$_ -]{0,29} $/, // table name
Isint: / ^ -?, D + $/, // integer
Istableothername: / ^ [\ u4e00 - \ u9fa5] {0,20} $/, // alias
isText_ 30: / ^ (\ w | w {1}) {0,30} $/, // match 30 characters. Characters can be letters, numbers, underscores and non letters. A Chinese character is counted as one character
isText_ 50: / ^ (\ w | w {1}) {0,50} $/, // matches 50 characters. Characters can be letters, numbers, underscores and non letters. A Chinese character is counted as one character
isText_ 20: / ^ (\ \ w | w {1}) {0,20} $/, // matches 20 characters. Characters can be letters, numbers, underscores and non letters. A Chinese character is counted as one character
isText_ 100: / ^ (\ w | w {1}) {0100} $/, // match 100 characters. Characters can be letters, numbers, underscores and non letters. A Chinese character is counted as one character
isText_ 250: / ^ (\ \ w | w {1}) {0250} $/, // matches 250 characters. Characters can be letters, numbers, underscores and non letters. A Chinese character is counted as one character
IDcard: / ^ [1-9] / D {7}} (1 [0-2]) ((0.d) | (1 [0-2]) ((([0.1241-2] \ \ d) | (3 [0-1-1]) \ \ D {3 [0-1]) \ \ D {3} (1-9) \ \ D {5} [1-9] / D {3} ((0.d) (1 [0-2)) ((([0.124; (1 [0-2]) ((([0.124124; (1 [0-2)) ((([0.124124u (1 [0-2]) (((([0.124124; (1 [0-2)) ((((1 | 2] | d) | 3 [0-1]), D {3} ([0-9] | x) $/, // ID card
Dadcardandadmin: / ^ (([1-9] \ \ D {7} ((0.d) | (1 [0-2]) (((([0.1-1-2] \ \ d) | 3 [0-1-1]) \ \ D {3} $[1-9] \ \ D {5} [1-9] \ \ D {5} [1-9] \ \ D {3} (1-9-9) \ \ D {3} (0-2) ((([0.1-2] \ \ d) | 3 [0-1-1]) \ \ D {3} ([0-1} ([0-1-2-2-2-2] \ \ d[0-9] | x)) | (admin)) $/, // ID card or admin account number
Tidcardtrim: / ^ s * ((([1-9] \ \ D {7} ((0 / D) | (1 [0-2]) ((([0-1-1-2)) ((([0-1-1-2] \ \ D-3 [0-1-1]) \ \ D {3} ([1-9] \ \ D {5} [1-9] \ \ D {3} ((0 / D) (1 [0-2]) ((([0-1-2-2)) (([0-1-2] \ \ d) | 3 [0-1-1]), D {3 [3-3-3-3-1] \ \ D ([3-3-3-3-3 [3-3} ([0-9] | x)) | (admin)) \ s * $/, // ID card
Num1: / ^ [1-9] * $/, // number
Imgtype: / image \ / (png|jpg| jpeg| GIF) $/, // upload image type
isChina: /^[\u4e00-\u9fa5]{2,8}$/,
Isnozeronumber: / ^ \ +? [1-9] - D * $/, // a positive integer greater than zero
Float: / ^ ^ D + (\.? ||||) $/, // matches a positive integer or decimal or 0. This special value
Htmlbody: / < body [^ >] * > (((. | [\ n / R]) *) < \ / body > / IM, // get the body content of the request page address
}
Verify ID card format
export const verifySfz = (sfz) => {
if (sfz.length !== 18) return false;
const a_i = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
const a_last = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
let sum = sfz
.slice(0, -1)
.split("")
.reduce((a, n, i) => {
return a + n * a_i[i];
}, 0);
return sfz.substr(-1) === a_last[sum % 11];
}