Created
May 28, 2015 08:59
-
-
Save bran921007/a264c3cd8dd3698e7ad6 to your computer and use it in GitHub Desktop.
Validar numero de telefono en muchos formatos y modificarlos segun un formato especifico
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
| The Expression | |
| ^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$ | |
| This regular expression will match any of the following U.S. numbers: | |
| 555 555 5555 | |
| (555) 555-5555 | |
| (555)555-5555 | |
| 555-555-5555 | |
| 555.555.5555 | |
| 5555555555 | |
| 0-000-000-0000 | |
| 0.000.000.0000 | |
| 0 000 000 0000 | |
| 00000000000 | |
| +0-000-000-0000 | |
| +0.000.000.0000 | |
| +0 000 000 0000 | |
| +00000000000 |
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
| public function formatPhone($phone) | |
| { | |
| if ( preg_match('/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$/', $phone, $matches)) { | |
| $matches[1] = ($matches[1]=='') ? '+1' : $matches[1]; | |
| return $matches[1].$matches[2].$matches[3].$matches[4]; | |
| } | |
| else { | |
| return return Response::json(array( | |
| 'success'=>'false', | |
| 'msg' =>'Invalid number format' | |
| )); | |
| // echo $tel; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment