Skip to content

Instantly share code, notes, and snippets.

@lkatney
Created November 18, 2014 08:58
Show Gist options
  • Save lkatney/0caca3639bfb9028f457 to your computer and use it in GitHub Desktop.
Save lkatney/0caca3639bfb9028f457 to your computer and use it in GitHub Desktop.
Method with regex to check email format - Apex
public Boolean checkValidUsername(String emailAddress){
String emailRegex = '([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})';
Pattern MyPattern = Pattern.compile(emailRegex);
Matcher MyMatcher = MyPattern.matcher(emailAddress);
if(MyMatcher.matches()){
return true;
}else{
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment