Here you can find the source of isEmailValid(String email)
Parameter | Description |
---|---|
String. Email address to validate |
public static boolean isEmailValid(String email)
//package com.java2s; //License from project: Open Source License import java.util.regex.*; public class Main { /** isEmailValid: Validate email address using Java reg ex. * This method checks if the input string is a valid email address. * @param email String. Email address to validate * @return boolean: true if email address is valid, false otherwise. *//* ww w.j av a 2 s .c om*/ public static boolean isEmailValid(String email) { boolean isValid = false; //Initialize reg ex for email. String expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; CharSequence inputStr = email; //Make the comparison case-insensitive. Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) { isValid = true; } return isValid; } }