Validating phoneNumbers

We want to validate Phone numbers, and there exists a validator in the laminas-i18n Package. There exists also the laminas-i18n-phone-number Package, which is not mentioned in the documentation, with an additional form element.

Which Package should we use? Are there any benefits when using the laminas-i18n-phone-number-Package?

Hey Mimmi,

it really depends on what you have in mind. If the dependency on an additional package is not so important and this package fulfils your requirements, use it. If the i18n package does not fulfil your requirements, you can also use your own validator for the Tel element from the laminas-form package and equip it with the required attributes and a corresponding specially written validator.

I would suggest that you try the laminas-i18n-phone-number package. If it is not enough, programme it yourself with your own validator.

The package is good. It is based on:

2 Likes

To expand on Frank’s response a little - the new laminas-i18n-phone-number is a better choice for validating any phone number because phone numbers are a moving target - giggsey/libphonenumber is a port of Google’s library, as such it’s kept up to date with carrier changes around the world, so, providing you composer update regularly, you’re much less likely to receive validation failures for actually valid phone numbers.

Unfortunately, the documentation for this library is not published anywhere at the moment, so you’ll have to look in the /docs directory.

2 Likes