Last active
February 5, 2016 20:27
-
-
Save ikarius6/e0e75dfdc691c9ef4fe4 to your computer and use it in GitHub Desktop.
Registro Federal de Contribuyentes (RFC) regex PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
RFC Regex by Jack | |
Valid: | |
JACK880229AA1 | |
JACK880229 | |
Invalid: | |
JACK880230AA1 | |
JACK890229AA1 | |
JACK880229AAA | |
*/ | |
$rfc = "LALA880229AA1"; | |
$pattern = "/^(?P<rfc>((([ÑA-Z|&]{3}|[A-Z]{4})\d{2}((0[1-9]|1[012])(0[1-9]|1\d|2[0-8])|(0[13456789]|1[012])(29|30)|(0[13578]|1[02])31)((\w{2})([A|0-9]{1}))?)$|^(([ÑA-Z|&]{3}|[A-Z]{4})([02468][048]|[13579][26])0229)((\w{2})([A|0-9]{1}))?))$/i"; | |
preg_match($pattern, $rfc, $matches); | |
print_r($matches['rfc']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muy bueno amigo, gracias.