-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9-validation.js
More file actions
26 lines (22 loc) · 819 Bytes
/
9-validation.js
File metadata and controls
26 lines (22 loc) · 819 Bytes
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
// Function to validate email
function validateEmail(email) {
const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return regex.test(email);
}
// Function to validate phone number (10-digit format)
function validatePhone(phone) {
const regex = /^\d{10}$/;
return regex.test(phone);
}
// Function to validate password (at least 8 characters, one number, one special character)
function validatePassword(password) {
const regex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
return regex.test(password);
}
// Example usage
const email = "test@example.com";
const phone = "1234567890";
const password = "Test@1234";
console.log(`Email valid: ${validateEmail(email)}`);
console.log(`Phone valid: ${validatePhone(phone)}`);
console.log(`Password valid: ${validatePassword(password)}`);