Skip to content

Commit

Permalink
Merge pull request #628 from IniyalPalanisamy/patch-6
Browse files Browse the repository at this point in the history
Update Email Validator
  • Loading branch information
anuragverma108 authored Oct 19, 2024
2 parents 85a4945 + 5bb93fb commit 2764f89
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions Email Validator
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 2764f89

Please sign in to comment.