-
Notifications
You must be signed in to change notification settings - Fork 0
/
next-php.php
executable file
·31 lines (28 loc) · 1.05 KB
/
next-php.php
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
function validateEmail(email) {
// Regular expression for validating email format
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
function validatePassword(password) {
// Check if password is at least 8 characters long and contains at least one number and one letter
const passwordRegex = /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$/;
return passwordRegex.test(password);
}
function validateCredentials(email, password) {
if (!validateEmail(email)) {
throw new Error("Invalid email format.");
}
if (!validatePassword(password)) {
throw new Error("Password must be at least 8 characters long and contain at least one letter and one number.");
}
return true; // If both validations pass
}
// Example usage
try {
const email = "test@example.com"; // Replace with user input
const password = "Password1"; // Replace with user input
validateCredentials(email, password);
console.log("Email and password are valid.");
} catch (error) {
console.error(error.message);
}