Skip to content

Commit

Permalink
Validate phone country against against a lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Apr 28, 2016
1 parent 89b72cf commit f0a0790
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"php": ">=5.4.0",
"illuminate/support": "~4.0|~5.0",
"illuminate/validation": "~4.0|~5.0",
"giggsey/libphonenumber-for-php": "~7.0"
"giggsey/libphonenumber-for-php": "~7.0",
"julien-c/iso3166": "~2.0"
},
"require-dev": {
"orchestra/testbench": "^3.1"
Expand Down
6 changes: 3 additions & 3 deletions src/PhoneValidator.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Propaganistas\LaravelPhone;

use Iso3166\Codes as ISO3166;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
Expand Down Expand Up @@ -230,15 +231,14 @@ public function isInputField($field)
}

/**
* Checks if the supplied string is a valid country code using some arbitrary country validation.
* If using a package based on umpirsky/country-list, invalidate the option 'ZZ => Unknown or invalid region'.
* Checks if the supplied string is a valid country code.
*
* @param string $country
* @return bool
*/
public function isPhoneCountry($country)
{
return (strlen($country) === 2 && ctype_alpha($country) && ctype_upper($country) && $country != 'ZZ');
return ISO3166::isValid($country);
}

/**
Expand Down

0 comments on commit f0a0790

Please sign in to comment.