View Single Post
Old 06-07-2008, 12:11 PM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

You could look to use strspn or strcspn rather than using the more 'powerful' (for want of a better term) regular expression functions.

PHP Code:
$test '+44-1234-5678';

if (
strcspn($test'1234567890+-'))
{
    echo 
'Test contains one or more invalid characters';
}
else
{
    echo 
'Test is nice and only contains digits, plus or dash';

Salathe is offline  
Reply With Quote