public function create_user($username, $password, $email, $phone, $bdate, $information, $interests, $city, $image) { $user = new User(); try { $user->set_username(Validation::username($username)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_password(Validation::password($password)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_email(Validation::email($email)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_phone(Validation::phone($phone)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_bdate(Validation::bdate($bdate)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_information(Validation::information($information)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_interests(Validation::interests($interests)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_city(Validation::city($city)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } try { $user->set_image(Validation::image($image)); } catch (Exception $ex) { echo 'Failed: ', $ex->getMessage(); exit; } return $user; }
/** * test pass through failure on postal * * @expectedException PHPUnit_Framework_Error * @return void */ public function testPassThroughMethodFailure() { Validation::phone('text', null, 'testNl'); }
/** * test the pass through calling of an alternate locale with postal() * * @return void **/ function testPassThroughMethod() { $this->assertTrue(Validation::postal('text', null, 'testNl')); $this->expectError('Could not find AUTOFAILValidation class, unable to complete validation.'); Validation::postal('text', null, 'AUTOFAIL'); $this->expectError('Method phone does not exist on TestNlValidation unable to complete validation.'); Validation::phone('text', null, 'testNl'); }
/** * testPhone method * * @access public * @return void */ function testPhone() { $this->assertFalse(Validation::phone('teststring')); $this->assertFalse(Validation::phone('1-(33)-(333)-(4444)')); $this->assertFalse(Validation::phone('1-(33)-3333-4444')); $this->assertFalse(Validation::phone('1-(33)-33-4444')); $this->assertFalse(Validation::phone('1-(33)-3-44444')); $this->assertFalse(Validation::phone('1-(33)-3-444')); $this->assertFalse(Validation::phone('1-(33)-3-44')); $this->assertFalse(Validation::phone('(055) 999-9999')); $this->assertFalse(Validation::phone('(155) 999-9999')); $this->assertFalse(Validation::phone('(595) 999-9999')); $this->assertFalse(Validation::phone('(555) 099-9999')); $this->assertFalse(Validation::phone('(555) 199-9999')); $this->assertTrue(Validation::phone('1 (222) 333 4444')); $this->assertTrue(Validation::phone('+1 (222) 333 4444')); $this->assertTrue(Validation::phone('(222) 333 4444')); $this->assertTrue(Validation::phone('1-(333)-333-4444')); $this->assertTrue(Validation::phone('1.(333)-333-4444')); $this->assertTrue(Validation::phone('1.(333).333-4444')); $this->assertTrue(Validation::phone('1.(333).333.4444')); $this->assertTrue(Validation::phone('1-333-333-4444')); }
/** * testPhone method * * @access public * @return void */ function testPhone() { $this->assertFalse(Validation::phone('teststring')); $this->assertFalse(Validation::phone('1-(33)-(333)-(4444)')); $this->assertFalse(Validation::phone('1-(33)-3333-4444')); $this->assertFalse(Validation::phone('1-(33)-33-4444')); $this->assertFalse(Validation::phone('1-(33)-3-44444')); $this->assertFalse(Validation::phone('1-(33)-3-444')); $this->assertFalse(Validation::phone('1-(33)-3-44')); $this->assertTrue(Validation::phone('(999) 999-9999')); $this->assertTrue(Validation::phone('1-(333)-333-4444')); $this->assertTrue(Validation::phone('1.(333)-333-4444')); $this->assertTrue(Validation::phone('1.(333).333-4444')); $this->assertTrue(Validation::phone('1.(333).333.4444')); $this->assertTrue(Validation::phone('1-333-333-4444')); }
$_SESSION["checkout"] = false; } if (!$_SESSION["checkout"]) { if (Validation::name($_POST["name"])) { $order->set_name($_POST["name"]); } else { $error = true; $msg = "Name format incorrect (it can only contain alphabets or spaces)<br>"; } if (Validation::address($_POST["address"])) { $order->set_address($_POST["address"]); } else { $error = true; $msg = $msg . "Address format incorrect (it cannot be empty)<br>"; } if (Validation::phone($_POST["phone"])) { $order->set_phone($_POST["phone"]); } else { $error = true; $msg = $msg . "Phone format incorrect, it must be of 8 digits only<br>"; } if (Validation::email($_POST["email"])) { $order->set_email($_POST["email"]); } else { $error = true; $msg = $msg . "Email format incorrect<br>"; } $order->update(); } if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($error) {
function phone_us($value) { // invalid_area_codes are accurate as of December 12, 2008. // this list inlcudes 2010's area code additions. $invalid_area_codes = array('230', '232', '233', '235', '236', '237', '238', '241', '243', '244', '245', '247', '249', '255', '257', '258', '259', '261', '263', '265', '266', '271', '272', '273', '274', '275', '277', '278', '279', '280', '282', '285', '286', '287', '288', '290', '291', '292', '293', '294', '295', '296', '297', '298', '299', '300', '322', '324', '326', '327', '328', '329', '332', '333', '335', '338', '342', '344', '346', '348', '349', '350', '353', '354', '355', '356', '357', '358', '359', '362', '363', '365', '366', '367', '368', '370', '371', '372', '373', '374', '375', '376', '377', '378', '379', '381', '382', '383', '384', '390', '391', '392', '393', '394', '395', '396', '397', '398', '399', '400', '420', '421', '422', '426', '427', '428', '429', '431', '433', '436', '437', '439', '444', '446', '448', '449', '451', '452', '453', '454', '455', '457', '458', '459', '460', '461', '462', '463', '465', '466', '467', '468', '471', '472', '474', '476', '477', '481', '482', '483', '485', '486', '487', '488', '489', '490', '491', '492', '493', '494', '495', '496', '497', '498', '499', '521', '522', '523', '524', '525', '526', '527', '528', '529', '532', '533', '534', '535', '536', '537', '538', '539', '542', '543', '544', '545', '546', '547', '548', '549', '550', '552', '553', '554', '555', '556', '558', '560', '565', '566', '568', '569', '572', '576', '577', '578', '579', '582', '583', '584', '588', '589', '590', '591', '592', '593', '594', '595', '596', '597', '598', '599', '600', '611', '621', '622', '624', '625', '629', '632', '633', '634', '635', '637', '638', '639', '640', '642', '643', '644', '645', '648', '652', '653', '654', '655', '656', '658', '663', '665', '666', '668', '672', '673', '674', '675', '676', '677', '680', '683', '685', '686', '687', '688', '690', '691', '692', '693', '694', '695', '696', '697', '698', '699', '700', '721', '722', '723', '725', '726', '728', '729', '733', '735', '736', '738', '739', '741', '742', '743', '744', '745', '746', '748', '749', '750', '751', '752', '753', '755', '756', '759', '761', '766', '768', '771', '776', '777', '782', '783', '788', '789', '790', '791', '792', '793', '794', '795', '796', '797', '798', '799', '820', '821', '823', '824', '826', '827', '834', '836', '837', '838', '839', '840', '841', '842', '846', '849', '851', '852', '853', '854', '861', '871', '873', '874', '875', '879', '890', '891', '892', '893', '894', '895', '896', '897', '898', '899', '900', '921', '922', '923', '924', '926', '927', '929', '930', '932', '933', '934', '938', '942', '943', '944', '945', '946', '950', '953', '955', '957', '958', '960', '961', '962', '963', '964', '965', '966', '967', '968', '969', '974', '976', '977', '981', '982', '983', '986', '987', '988', '990', '991', '992', '993', '994', '995', '996', '997', '998', '999'); // phone number prefixes can't be with 555 (sorry, 555 only works in the movies) $invalid_prefixes = array('555'); $valid = false; $validation = new Validation(); $default_valid = $validation->phone($value['value'], null, 'us'); if ($default_valid) { $working_value = preg_replace('/[^0-9]/i', '', $value['value']); if (strlen($working_value) == 10) { $areaCode = substr($working_value, 0, 3); $prefix = substr($working_value, 3, 3); $suffix = substr($working_value, 6, 4); } else { if (strlen($working_value) == 11) { $areaCode = substr($working_value, 1, 3); $prefix = substr($working_value, 4, 3); $suffix = substr($working_value, 7, 4); } } if (!empty($areaCode) && !empty($prefix) && !empty($suffix)) { if (!in_array($areaCode, $invalid_area_codes) && intval($areaCode) > 200 && (!in_array($prefix, $invalid_prefixes) && intval($prefix) > 199)) { $valid = true; } } } return $valid; }