Skip to content

Instantly share code, notes, and snippets.

@msng
Created November 28, 2011 01:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save msng/1398645 to your computer and use it in GitHub Desktop.
Save msng/1398645 to your computer and use it in GitHub Desktop.
Another CakePHP validation rule for email, accepting irregular addresses once allowed by docomo and au
<?php
//For PHP 5.3.x or later
public function emailExtended($data, $deep = false) {
$pattern = '/.+@(docomo|ezweb)\.ne\.jp$/i';
$check = preg_replace_callback($pattern, function($matches) {
$patterns = array('/\.{2,}/', '/\.@/');
$replacements = array('.', '@');
return preg_replace($patterns, $replacements, $matches[0]);
}, array_shift($data));
return Validation::email($check, $deep);
}
<?php
//For PHP 5.2.x or earlier
public function emailExtended($data, $deep = false) {
$pattern = '/.+@(docomo|ezweb)\.ne\.jp$/i';
$check = preg_replace_callback($pattern, create_function('$matches', '
$patterns = array("/\.{2,}/", "/\.@/");
$replacements = array(".", "@");
return preg_replace($patterns, $replacements, $matches[0]);
'), array_shift($data));
return Validation::email($check, $deep);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment