Skip to content

Instantly share code, notes, and snippets.

@ikarius6
Last active February 5, 2016 20:27
Show Gist options
  • Save ikarius6/e0e75dfdc691c9ef4fe4 to your computer and use it in GitHub Desktop.
Save ikarius6/e0e75dfdc691c9ef4fe4 to your computer and use it in GitHub Desktop.
Registro Federal de Contribuyentes (RFC) regex PHP
<?php
/*
RFC Regex by Jack
Valid:
JACK880229AA1
JACK880229
Invalid:
JACK880230AA1
JACK890229AA1
JACK880229AAA
*/
$rfc = "LALA880229AA1";
$pattern = "/^(?P<rfc>((([ÑA-Z|&amp;]{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|&amp;]{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']);
@vaporic
Copy link

vaporic commented Feb 5, 2016

Muy bueno amigo, gracias.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment