I want to validate an email introduced inside an EditText and this the code that I already have :
public static boolean isValidEmail(String str) { boolean isValid = false; String expression = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; CharSequence inputStr = str; Pattern pattern = Pattern.compile(expression); Matcher matcher = pattern.matcher(inputStr); if (matcher.matches()) { isValid = true; } return isValid; } The problem is that when I am using _ and - these characters in starting of email id, no error is showing, but when i use any other character, an error is shown.
Now i want that when ever i used any special character in starting of email id, an error must be shown. no special character should be allowed in starting of email id.
what should i do for this..?
[email protected]is also the valid email id.