Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Added I18n PhoneNumber validator based off of country #4127

Merged
merged 1 commit into from Apr 3, 2013

Conversation

Projects
None yet
7 participants
Contributor

mwillbanks commented Mar 27, 2013

I am breaking off items from #3884 to make it easier to be able to merge each individually. Please see original PR for several notes. None were given on phone number implementation.

Phone Number

The Phone Number validator is based on libPhoneNumber's XML file. It is a multi-dimensional hash that takes the country code as a key then several subkeys for possible types, national types and separated by types of numbers. The country is primarily used so that you will only need to validate against a subset of items. A country is required.
Basic Usage:

$validator = new \Zend\I18n\Validator\PhoneNumber();
$validator->setCountry('US'); // could be omitted since AD below is a country
$validator->isValid('2015550123');

// input filter with context
$filter = new InputFilter();
$factory = new InputFactory();
// assumption here is that we have a country field coming through the context
$filter->add($factory->createInput(array(
    'name' => 'country',
    'required' => true,
    'validators' => array(
        'name' => 'Zend\I18n\Validator\Country', // separate PR coming later
    ),
)));
$filter->add($factory->createInput(array(
    'name' => 'phoneNumber',
    'required' => true,
    'filters' => array(
        'Digits',
    ),
    'validators' => array(
        'name' => 'Zend\I18n\Validator\PhoneNumber',
        'options' => array(
            'country' => 'country',
        ),
    ),
)));
Member

EvanDotPro commented Mar 27, 2013

Thank you. Thank you. Thank you. Thank you.

Contributor

mwillbanks commented Mar 27, 2013

@EvanDotPro i think it may need some additional work to fit your use case a bit better but it should be customizable enough for now. I think it could possibly go through all patterns to find possible matches and then attempt to figure out a country or something like that but for now it requires a country :)

Contributor

ThomasCantonnet commented Mar 27, 2013

I am wondering if there isn't a better way to implement a 200kb array in the validator, I was looking at SplFixedArray but that would require a second array for indexes. I wonder what the benchmarks are on memory usage on this PR.

More generally, the question is, is this the best way to use large fixed datasets accross ZF2.

Member

DASPRiD commented Mar 27, 2013

@mwillbanks About the large array problem @ThomasCantonnet mentioned:

I'd suggest to split the country data into individual files (Zend/I18n/Validator/PhoneNumer/[a-z]{2}.php). and then just load them as required:

$specs = require __DIR__ . '/PhoneNumber/' . $countryCode . '.php';

This should solve a possible memory problem quite a bit.

Contributor

mwillbanks commented Mar 27, 2013

I'll refactor this a bit; likely tonight ;)

Contributor

mwillbanks commented Mar 29, 2013

Rebased, force pushed, adjusted for feedback.
@EvanDotPro @DASPRiD care to review?

@weierophinney weierophinney was assigned Apr 3, 2013

@weierophinney weierophinney added a commit that referenced this pull request Apr 3, 2013

@weierophinney weierophinney Merge pull request #4127 from mwillbanks/feature/i18n-validator-phone…
…number

Added I18n PhoneNumber validator based off of country
df63d3d

@weierophinney weierophinney added a commit that referenced this pull request Apr 3, 2013

@weierophinney weierophinney Merge branch 'feature/4127' into develop
Close #4127
efb9739

@weierophinney weierophinney merged commit a730867 into zendframework:develop Apr 3, 2013

1 check passed

default The Travis build passed
Details

@mwillbanks mwillbanks deleted the mwillbanks:feature/i18n-validator-phonenumber branch Apr 4, 2013

wohugb commented Sep 24, 2013

how to set only for mobile?
find it:

'allowed_types' => array('mobile'),

Member

Thinkscape commented Oct 12, 2013

#5150 is still hanging ...

@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge pull request zendframework/zendframework#4127 from mwillbanks/f…
…eature/i18n-validator-phonenumber

Added I18n PhoneNumber validator based off of country
06120aa

@weierophinney weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015

@weierophinney weierophinney Merge branch 'feature/4127' into develop 2d12221
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment