Show
Ignore:
Timestamp:
12/07/2007 01:26:22 PM (13 months ago)
Author:
Shadowhand
Message:

Added valid::phone($number)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/helpers/valid.php

    r1415 r1446  
    216216 
    217217        /** 
     218         * Checks if a phone number is valid. 
     219         * 
     220         * @todo  This function is not l10n-compatible. 
     221         * 
     222         * @param   string   phone number to check 
     223         * @return  boolean 
     224         */ 
     225        public static function phone($number) 
     226        { 
     227                $number = preg_replace('/[^0-9]/', '', $number); 
     228 
     229                if (strlen($number) > 10 AND substr($number, 0, 1) === '1') 
     230                { 
     231                        // Remove the "1" prefix from the number 
     232                        $number = substr($number, 1); 
     233                } 
     234 
     235                // If the length is not 10, it's not a valid number 
     236                return (strlen($number) === 10); 
     237        } 
     238 
     239        /** 
    218240         * Method: alpha 
    219241         *  Checks whether a string consists of alphabetical characters only