Hi, I'm trying to validate a phone number... And I need a Regular Expression to test phone numbers like this: 02x xxx xx xx Or 03x xxx xx xx... How can I do it? With and without the spaces between numbers... Could you please help me on this? Many Thanks in advance!!
Here's a class I wrote for someone else on DP: class phoneNumber { public $nums; function __construct($num) { $this->set($num); } function set($num) { $num = preg_split('//', $num); foreach ($num as $key => $value) if (!is_numeric($value)) unset($num[$key]); if (count($num) < 10 OR count($num) > 11) { trigger_error("WOOPS! The phone number is not valid. The length ".count($num)." isn't enough."); exit; } $num = array_merge(array(), $num); $this->nums = $num; } function get() { $nums = $this->nums; if (count($nums) == 11) { $num = $nums[1].$nums[2].$nums[3]."-".$nums[4].$nums[5].$nums[6]."-".$nums[7].$nums[8].$nums[9].$nums[10]; } else if (count($nums) == 10) { $num = $nums[0].$nums[1].$nums[2]."-".$nums[3].$nums[4].$nums[5]."-".$nums[6].$nums[7].$nums[8].$nums[9]; } return $num; } } Code (markup): usage: $somePhoneNumber = "1 234 567 8901" $pn = new phoneNumber($somePhoneNumber); echo $pn->get(); Code (markup): Not a regex, but better IMO.
I need to use the Regular Expression inside a Mootools Javascript Form.Validator script... Im on Mac, any tool for Mac Osx? Thanks.