-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvalidationService.ts
35 lines (28 loc) · 977 Bytes
/
validationService.ts
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
class validationService {
// Validation method for email
static validateEmail(email: any) {
const emailRegex = /^\w+([.-]?\w+)*@\w+([.-]?\w+)*(\.\w{2,3})+$/;
if (email.length < 5 || email.length > 50) {
return 'Email must be between 5 and 50 characters.';
}
if (!emailRegex.test(email)) {
return 'Please enter a valid email address.';
}
return '';
}
// Validation method for first name
static validateFirstName(firstName: any) {
if (firstName.length < 2 || firstName.length > 15) {
return 'First name must be between 2 and 15 characters.';
}
return '';
}
// Validation method for last name
static validateLastName(lastName: any) {
if (lastName.length < 2 || lastName.length > 15) {
return 'Last name must be between 2 and 15 characters.';
}
return '';
}
}
export default validationService;