diff --git a/CHANGELOG.md b/CHANGELOG.md index b06b6469d..03d8b2d6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,3 +103,5 @@ Branch CRUD-Init - css: add a margin on the button "delete entry" in collection - module `show_hide`: add the possibility to launch a show hide manually and not on page loading. Useful when show/hide occurs in collection. - module `show_hide`: add events to module +- [phonenumber validation] allow to validate against mobile **or** landline/voip phonenumbers; + diff --git a/Phonenumber/PhonenumberHelper.php b/Phonenumber/PhonenumberHelper.php index 4e06472d3..5bb362e15 100644 --- a/Phonenumber/PhonenumberHelper.php +++ b/Phonenumber/PhonenumberHelper.php @@ -122,6 +122,24 @@ class PhonenumberHelper return \in_array($validation, [ 'landline', 'voip' ]); } + /** + * Return true if the phonenumber is a landline or voip phone. Return always false + * if the validation is not configured. + * + * @param string $phonenumber + * @return bool + */ + public function isValidPhonenumberAny($phonenumber) : bool + { + $validation = $this->performTwilioLookup($phonenumber); + + if (NULL === $validation) { + return false; + } + + return \in_array($validation, [ 'landline', 'voip', 'mobile' ]); + } + public function format($phonenumber) { return $this->performTwilioFormat($phonenumber); diff --git a/Resources/translations/validators.fr.yml b/Resources/translations/validators.fr.yml index ab3596c79..766bee9da 100644 --- a/Resources/translations/validators.fr.yml +++ b/Resources/translations/validators.fr.yml @@ -17,3 +17,4 @@ This username or email does not exists: Cet utilisateur ou email n'est pas prés #phonenumber This is not a landline phonenumber: Ce numéro n'est pas une ligne fixe valide This is not a mobile phonenumber: Ce numéro n'est pas un numéro de portable valide +This is not a valid phonenumber: Ce numéro de téléphone n'est pas valide diff --git a/Validation/Constraint/PhonenumberConstraint.php b/Validation/Constraint/PhonenumberConstraint.php index 9e322285d..cf4479456 100644 --- a/Validation/Constraint/PhonenumberConstraint.php +++ b/Validation/Constraint/PhonenumberConstraint.php @@ -21,7 +21,7 @@ use Symfony\Component\Validator\Constraint; /** * - * + * @Annotation */ class PhonenumberConstraint extends Constraint { @@ -29,10 +29,12 @@ class PhonenumberConstraint extends Constraint public $notLandlineMessage = "This is not a landline phonenumber"; + public $notValidMessage = "This is not a valid phonenumber"; + /** * The type of phone: landline (not able to receive sms) or mobile (can receive sms) * - * @var string 'landline' or 'mobile' + * @var string 'landline', 'mobile' or 'any' */ public $type = null; diff --git a/Validation/Validator/ValidPhonenumber.php b/Validation/Validator/ValidPhonenumber.php index 971dedc25..127bfad33 100644 --- a/Validation/Validator/ValidPhonenumber.php +++ b/Validation/Validator/ValidPhonenumber.php @@ -70,10 +70,14 @@ class ValidPhonenumber extends ConstraintValidator $isValid = $this->phonenumberHelper->isValidPhonenumberMobile($value); $message = $constraint->notMobileMessage; break; + case 'any': + $isValid = $this->phonenumberHelper->isValidPhonenumberAny($value); + $message = $constraint->notValidMessage; + break; default: throw new \LogicException(sprintf("This type '%s' is not implemented. " - . "Possible values are 'mobile', 'landline'"), $constraint->type); + . "Possible values are 'mobile', 'landline' or 'any'", $constraint->type)); } if (FALSE === $isValid) {