Regular Expression for email validation using apex in Salesforce

String strMail = 'testmail@gmail.com'; 
if(!Pattern.matches('[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}', strMail))
{                        
    //Your error message
}

Leave a Reply