Here is a very useful regular expression. It allows validation of US and non-US phone numbers.
It allows ‘+’ prefix and ’spaces’ and ‘-’ characters.
It should work with all the current phone numbers in the world. If you find one that doesn’t match, please comment about it.
Regular expression :
/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/
CakePHP validation rule :
‘phone’ => array(
‘notempty’ => array(
‘rule’ => array(’custom’, ‘/^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,5})|(\(?\d{2,6}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/’),
‘required’ => false,
‘allowEmpty’ => true,
‘message’ => ‘Invalide phone number’
)
)
