I'm trying to find out how to remove all invalid characters in an email address.
Ex: email="taeo͝';[email protected]"(. is an email character) and the result should be: email = "[email protected]"
I'm using the following email pattern:
String email_pattern = "^[^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$]";
String modifiedEmail = email.replaceAll(email_pattern,"");
But the above code is giving the result: email = "[email protected]" but expected "[email protected]"
Any suggestions or a better approach would be appreciated.