Skip to content

Instantly share code, notes, and snippets.

@abdullahpazarbasi
Created August 25, 2021 11:29
Show Gist options
  • Save abdullahpazarbasi/3bd96a31f6c42fd181fd9a8b2f868d98 to your computer and use it in GitHub Desktop.
Save abdullahpazarbasi/3bd96a31f6c42fd181fd9a8b2f868d98 to your computer and use it in GitHub Desktop.
E-mail Regular Expression (Regex) Pattern PCRE
<?php
$sPattern = '^[^<>()[\]\\.,;:\s@"]+(?:\.[^<>()[\]\\.,;:\s@"]+)*@(?:xn--)?[a-zA-Z][a-zA-Z\d]*(?:-[a-zA-Z\d]+)*\.(?!local)[a-zA-Z]{2,32}(?:\.[a-zA-Z]{2})?$';
//
$sSubject = 'john.doe@example.org';
//
$aMatches = [];
if (preg_match($sPattern, $sSubject, $aMatches)) {
echo 'ok';
}
else {
echo 'oops!';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment