-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Email and Password validation class added
- Loading branch information
Showing
2 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.readitai; | ||
|
||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class Validator { | ||
|
||
// Regular expression patterns for email and password validation | ||
private static final String EMAIL_PATTERN = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; | ||
private static final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[!@#$%^&*()_+\\-=\\[\\]{};':\"\\\\|,.<>\\/?]).{7,}$"; | ||
|
||
private static final Pattern emailPattern = Pattern.compile(EMAIL_PATTERN); | ||
private static final Pattern passwordPattern = Pattern.compile(PASSWORD_PATTERN); | ||
|
||
public static boolean isValidEmail(String email) { | ||
Matcher matcher = emailPattern.matcher(email); | ||
return matcher.matches(); | ||
} | ||
|
||
public static boolean isValidPassword(String password) { | ||
Matcher matcher = passwordPattern.matcher(password); | ||
return matcher.matches(); | ||
} | ||
} | ||
|