Search code examples
phpvalidationphone-number

Does Zend2 frame work allow for phone numbers as low as two digits?


I have done testing work and min 4 digits are required for phone numbers..

How (if posible) to allow the application based on Zend2 to validate phone numbers as low as 2 digits, like: ‘11’?


Solution

  • If your app is already doing validation via a Zend\Validator chain then you probably want to do it via one of the existing validators. This will keep the validation in one place and prevent you from having to write any custom code. If Zend\I18n\Validator\PhoneNumber is already in your chain then you can check to see if there's a supported type for your country that matches your desired pattern. See the files in zend-i18n/src/Validator/PhoneNumber. (This is probably not likely for a two-digit number, that seems pretty custom.) If not, you can probably inject a Zend\Validator\Between or a Zend\Validator\StringLength object into your validator chain via a config file change.