View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Validate_Phone
{zone-data}

{zone-data:proposer-list}
[~thomas]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
1.0 - 11 June 2009: Initial Draft.
{zone-data}

{zone-data:overview}
Zend_Validate_Phone is a validator which checks if a given input conforms a expected format for a phone number.
{zone-data}

{zone-data:references}
* [Wikipedia - Telephone numbers|http://en.wikipedia.org/wiki/Telephone_number]
* [Wikipedia - E.123|http://en.wikipedia.org/wiki/E.123]
* [ITU-T|http://www.itu.int/rec/recommendation.asp?type=items&lang=e&parent=T-REC-E.123-200102-I]
{zone-data}

{zone-data:requirements}
* This component *will* check if a string conforms a expected phone number format
* This component *will not* change the format, only check
* This component *will* accept national and international formats
* This component *will* also allow to check if a given number conforms a given country or multiple countries
* This component *will not* check if a given number does exist
{zone-data}

{zone-data:dependencies}
* Zend_Validate_Exception
* Zend_Validate_Abstract
{zone-data}

{zone-data:operation}
The component validates if a given string conforms a expected input. The expected format can be a national number, a international number, or a self defined format. It can also check if number parts are given. (country code, extension).
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] Proposal finished
* Milestone 2: Proposal accepted
* Milestone 3: Working implementation
* Milestone 4: Unit tests
* Milestone 5: Documentation
* Milestone 6: Moved to core
{zone-data}

{zone-data:class-list}
* Zend_Validate_Phone
{zone-data}

{zone-data:use-cases}
||UC-01||
Simply validation... accepts all sorts of phone numbers
{code}
$validate = new Zend_Validate_Phone();
$validate->isValid('(123) 456789');
$validate->isValid('+49 (123) 456789');
$validate->isValid('0049 123 456789-123');
$validate->isValid('456789 - 123');
$validate->isValid('Phone: 456 - 132'); // FALSE
{code}

||UC-02||
Validation for one country
{code}
$validate = new Zend_Validate_Phone('de_AT');
$validate->isValid('(1234) 56789');
$validate->isValid('+49 (123) 456789'); // FALSE
$validate->isValid('0049 123 456789-123'); // FALSE
$validate->isValid('0043 123 456789-123');
$validate->isValid('456789 - 123');
$validate->isValid('Phone: 456 - 132'); // FALSE
{code}

||UC-02||
Validation with set options (no extension)
{code}
$validate = new Zend_Validate_Phone(array('locale' => 'de_AT', 'format' => Zend_Validate_Phone::NO_EXTENSION));
$validate->isValid('(1234) 56789');
$validate->isValid('+49 (123) 456789'); // FALSE
$validate->isValid('0049 123 456789-123'); // FALSE
$validate->isValid('0043 123 456789-123'); // FALSE because of extension
$validate->isValid('456789 - 123'); // FALSE
$validate->isValid('456789'); // FALSE
$validate->isValid('Phone: 456 - 132'); // FALSE
{code}

||UC-03||
Validation with set options (national format)
{code}
$validate = new Zend_Validate_Phone(array('locale' => 'de_AT', 'format' => Zend_Validate_Phone::NATIONAL));
$validate->isValid('(1234) 56789');
$validate->isValid('+49 (123) 456789'); // FALSE
$validate->isValid('0049 123 456789-123'); // FALSE
$validate->isValid('0043 123 456789-123'); // FALSE because of international format
$validate->isValid('456789 - 123');
$validate->isValid('Phone: 456 - 132'); // FALSE
{code}

||UC-04||
Validation with self defined format
{code}
$validate = new Zend_Validate_Phone(array('locale' => 'de_AT', 'format' => array('TCN' => 4, 'CCN' => 3, 'LCN' => '5-7', 'EXT' => 0)));
{code}
The resulting number would be like
Territory code: 4 numbers
City code: 3 numbers
Local code: 5 to 7 numbers
Extension: 0 numbers

+49 1234 456789 -> false -> territory code 2 and not 4
0049 (1234) 456789 -> true
0049 (1234) 456789-123 -> false, extension given
{zone-data}

{zone-data:skeletons}
{code}
class Zend_Validate_Phone extends Zend_Validate_Abstract {}

const NATIONAL;
const INTERNATIONAL;
const NO_EXTENSION;

public function __construct($parameters);
public function getTerritory();
public function setTerritory($territory);
public function getFormat();
public function setFormat($format);
public function isValid($input);
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>