laminas / laminas-i18n

Provide translations for your application, and filter and validate internationalized values
https://docs.laminas.dev/laminas-i18n/
BSD 3-Clause "New" or "Revised" License
46 stars 27 forks source link

PhoneNumber requires country code #3

Closed weierophinney closed 4 months ago

weierophinney commented 4 years ago

Use case, UK business website with enquiry form for UK customers. They are not expected to enter the country code for their phone number. An 11 digit number beginning with 0 is not considered valid. e.g. 0161 123 4567 (calling internationally it would be +44 161 123 4567). The issue only occurs with UK mobile numbers in my testing and the above is actually correct.

Code to reproduce the issue

$phoneNumber = new \Zend\I18n\Validator\PhoneNumber();
$phoneNumber->isValid('07875121234');

Expected results

Considered valid.

Actual results

Considered invalid.

Not sure of an easy fix for this, or whether the docs should state that the country code is expected?


Originally posted by @internalsystemerror at https://github.com/zendframework/zend-i18n/issues/111

weierophinney commented 4 years ago

I believe this is something the Google library takes into account... Looking at an alternative implementation it works as expected: https://giggsey.com/libphonenumber/.


Originally posted by @internalsystemerror at https://github.com/zendframework/zend-i18n/issues/111#issuecomment-495570448

weierophinney commented 4 years ago

@internalsystemerror The current problem: the patterns for phone numbers in zend-i18n are very old. We need a script to update these patterns and have to rework all unit tests which belongs to the PhoneNumber validator.


Originally posted by @froschdesign at https://github.com/zendframework/zend-i18n/issues/111#issuecomment-495573898

weierophinney commented 4 years ago

Sorry, this issue report is a feature request and not a bug. The bug are the outdated phone number patterns which are covered in separate issue reports.


I like this feature request because it would be a great improvement for this component!


Originally posted by @froschdesign at https://github.com/zendframework/zend-i18n/issues/111#issuecomment-495580536

weierophinney commented 4 years ago

On further investigation, the original example given above is in fact valid, and it's only UK mobiles which have an issue: e.g. 0787 512 1234.


Originally posted by @internalsystemerror at https://github.com/zendframework/zend-i18n/issues/111#issuecomment-495590036

weierophinney commented 4 years ago

@internalsystemerror No problem. We have to write unit tests anyway.


Originally posted by @froschdesign at https://github.com/zendframework/zend-i18n/issues/111#issuecomment-495590851

froschdesign commented 4 months ago

Fixed with: https://github.com/laminas/laminas-i18n-phone-number