aboutsummaryrefslogtreecommitdiff
path: root/src/constants/regex.ts
blob: 7de364920a14336432410dcc1fb461c69b7a4482 (plain)
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
/**
 * The email regex has complex constraints compliant with RFC 5322 standards. More details can be found [here](https://emailregex.com/).
 */
export const emailRegex: RegExp = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

/**
 * The password regex has the following constraints
 * - min. 8 chars, max. 120 chars ({8,120})
 * - at least one numeric digit ([0-9])
 * - at least one lowercase letter ([a-z])
 * - at least one uppercase letter ([A-Z])
 * - at least one special character ([^a-zA-z0-9])
 */
export const passwordRegex: RegExp = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z0-9])(?!.*\s).{8,120}$/;

/**
 * The username regex has the following constraints
 * - min. 3 chars, max. 30 chars ({6,30})
 * - match only alphanumerics, underscores, and periods
 */
export const usernameRegex: RegExp = /^[a-zA-Z0-9_.]{3,30}$/;

/**
 * The name regex has the following constraints
 * - min. 2 chars, max. 20 chars ({2,20})
 * - match alphanumerics, apostrophes, commas, periods, dashes, and spaces
 */
export const nameRegex: RegExp = /^[A-Za-z'\-,. ]{2,20}$/;

/**
 * The website regex has the following constraints
 * - starts with http:// or https://
 * - min. 2 chars, max. 50 chars on website name
 * - match alphanumerics, and special characters used in URLs
 */
export const websiteRegex: RegExp = /^$|^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,50}\.[a-zA-Z0-9()]{2,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]{0,35})$/;

/**
 * The website regex has the following constraints
 * - max. 150 chars for bio
 * - match alphanumerics, and special characters used in URLs
 */
export const bioRegex: RegExp = /^[\s\S]{1,150}$/;

/**
 * The gender regex has the following constraints
 * - max. 20 chars for bio
 * - match alphanumerics, hyphens, and whitespaces
 */
export const genderRegex: RegExp = /^$|^[A-Za-z\- ]{2,20}$/;

/**
 * The phone regex has the following constraints
 *  - must be 10 digits
 *  - accepts 0123456789
 *
 */
export const phoneRegex: RegExp = /^[0-9]{10}$/;

/**
 * The code regex has the following constraints
 *  - must be 6 digits
 */
export const codeRegex: RegExp = /([0-9]{6})/;