Re: RegEx -- help

From: Date: Fri, 10 Oct 2003 18:21:05 +0000
Subject: Re: RegEx -- help
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165777@lists.php.net to get a copy of this message
Untested: function fixhisnumber($str){ //remove all but numbers $str = preg_replace("/[^0-9]/","",$str); //append 1, unless it's already there $str = $str[0] == '1'? $str:"1".$str; if (strlen($str) == 10) return $str; else return -1; } Mohamed~ On Fri, 2003-10-10 at 14:01, Lists wrote: > I do not know if this is the right list, but if someone could help me with > the following > > I need a function that does this: > > function phone($num) { > > take num and remove anything that is not a number > ex: () - / > > > If there is not 1 at the start, add a one to the start of the number. > > make sure that the number is 10 digits (if not return -1) > > > } > > Thank you for your help, > > Michael

« previous php.general (#165777) next »