From 5bb93fbbfd44495a55bf9ece5b88abc68c5de7ad Mon Sep 17 00:00:00 2001 From: Iniyal Palanisamy <123928113+IniyalPalanisamy@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:35:07 +0530 Subject: [PATCH] Update Email Validator --- Email Validator | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/Email Validator b/Email Validator index 2d5c6265..63a7d020 100644 --- a/Email Validator +++ b/Email Validator @@ -1,35 +1,27 @@ import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class EmailValidation { - public static boolean isValidEmail(String email) { - // Regular expression for email validation - String emailRegex = "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"; - - // Compile the regular expression - Pattern pattern = Pattern.compile(emailRegex); - - // Match the email with the regex pattern - Matcher matcher = pattern.matcher(email); - - // Return true if it matches, false otherwise - return matcher.matches(); - } +public class LoginPage { + public static void main(String[] args) { // Create a scanner object for user input Scanner scanner = new Scanner(System.in); // Prompt the user to enter an email address - System.out.print("Enter an email address to validate: "); + System.out.print("Enter your email address: "); String email = scanner.nextLine(); - // Check if the email is valid and print the result - if (isValidEmail(email)) { - System.out.println("The email address \"" + email + "\" is valid."); + // Validate the email address + if (EmailValidation.isValidEmail(email)) { + // If valid, prompt for password + System.out.print("Enter your password: "); + String password = scanner.nextLine(); + + // Simulate login (for demonstration purposes) + // In a real application, you would check the credentials against a database + System.out.println("Login successful for email: " + email); } else { - System.out.println("The email address \"" + email + "\" is invalid."); + // If invalid, print an error message + System.out.println("The email address \"" + email + "\" is invalid. Please enter a valid email."); } // Close the scanner to prevent resource leaks