コード例 #1
0
ファイル: ValidatorTest.php プロジェクト: nilamdoc/KYCGlobal
 /**
  * Tests credit card validation for numbers in various vendors' formats.
  */
 public function testCreditCardValidation()
 {
     /* American Express */
     $this->assertTrue(Validator::isCreditCard('370482756063980', 'amex'));
     $this->assertTrue(Validator::isCreditCard('3491-0643-3773-483', 'amex'));
     $this->assertTrue(Validator::isCreditCard('344671486204764', 'amex'));
     $this->assertTrue(Validator::isCreditCard('344042544509943', 'amex'));
     $this->assertTrue(Validator::isCreditCard('377147515754475', 'amex'));
     $this->assertTrue(Validator::isCreditCard('375239372816422', 'amex'));
     $this->assertTrue(Validator::isCreditCard('376294341957707', 'amex'));
     $this->assertTrue(Validator::isCreditCard('341779292230411', 'amex'));
     $this->assertTrue(Validator::isCreditCard('341646919853372', 'amex'));
     $this->assertTrue(Validator::isCreditCard('348498616319346', 'amex', array('deep' => true)));
     $this->assertFalse(Validator::isCreditCard('5610376649499352', 'amex'));
     /* BankCard */
     $this->assertTrue(Validator::isCreditCard('5610 7458 6741 3420', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5610376649499352', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5610091936000694', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5602248780118788', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5610631567676765', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5602238211270795', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5610173951215470', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5610139705753702', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5602226032150551', 'bankcard'));
     $this->assertTrue(Validator::isCreditCard('5602223993735777', 'bankcard'));
     $this->assertFalse(Validator::isCreditCard('30155483651028', 'bankcard'));
     /* Diners Club 14 */
     $this->assertTrue(Validator::isCreditCard('30155483651028', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36371312803821', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38801277489875', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30348560464296', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30349040317708', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36567413559978', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36051554732702', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30391842198191', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30172682197745', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30162056566641', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30085066927745', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36519025221976', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30372679371044', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38913939150124', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36852899094637', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30138041971120', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36184047836838', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30057460264462', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38980165212050', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30356516881240', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38744810033182', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30173638706621', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30158334709185', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30195413721186', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38863347694793', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30275627009113', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30242860404971', 'diners'));
     $this->assertTrue(Validator::isCreditCard('30081877595151', 'diners'));
     $this->assertTrue(Validator::isCreditCard('38053196067461', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36520379984870', 'diners'));
     /* 2004 MasterCard/Diners Club Alliance International 14 */
     $this->assertTrue(Validator::isCreditCard('36747701998969', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36427861123159', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36150537602386', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36582388820610', 'diners'));
     $this->assertTrue(Validator::isCreditCard('36729045250216', 'diners'));
     /* 2004 MasterCard/Diners Club Alliance US & Canada 16 */
     $this->assertTrue(Validator::isCreditCard('5597511346169950', 'diners'));
     $this->assertTrue(Validator::isCreditCard('5526443162217562', 'diners'));
     $this->assertTrue(Validator::isCreditCard('5577265786122391', 'diners'));
     $this->assertTrue(Validator::isCreditCard('5534061404676989', 'diners'));
     $this->assertTrue(Validator::isCreditCard('5545313588374502', 'diners'));
     $this->assertFalse(Validator::isCreditCard('6011802876467237', 'diners'));
     /* Discover */
     $this->assertTrue(Validator::isCreditCard('6011802876467237', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6506432777720955', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6011126265283942', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6502187151579252', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6506600836002298', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6504376463615189', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6011440907005377', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6509735979634270', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6011422366775856', 'disc'));
     $this->assertTrue(Validator::isCreditCard('6500976374623323', 'disc'));
     $this->assertFalse(Validator::isCreditCard('201496944158937', 'disc'));
     /* enRoute */
     $this->assertTrue(Validator::isCreditCard('201496944158937', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('214945833739665', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('214982692491187', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('214901395949424', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('201480676269187', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('214911922887807', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('201485025457250', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('201402662758866', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('214981579370225', 'enroute'));
     $this->assertTrue(Validator::isCreditCard('201447595859877', 'enroute'));
     $this->assertFalse(Validator::isCreditCard('210034762247893', 'enroute'));
     /* JCB 15 digit */
     $this->assertTrue(Validator::isCreditCard('210034762247893', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('180078671678892', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('180010559353736', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('210095474464258', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('210006675562188', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('210063299662662', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('180032506857825', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('210057919192738', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('180031358949367', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('180033802147846', 'jcb'));
     /* JCB 16 digit */
     $this->assertTrue(Validator::isCreditCard('3096806857839939', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158699503187091', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112549607186579', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112332922425604', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112001541159239', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112162495317841', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3337562627732768', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3337107161330775', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528053736003621', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528915255020360', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3096786059660921', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528264799292320', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3096469164130136', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112127443822853', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3096849995802328', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528090735127407', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3112101006819234', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3337444428040784', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3088043154151061', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3088295969414866', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158748843158575', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158709206148538', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158365159575324', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158671691305165', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528523028771093', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3096057126267870', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3158514047166834', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528274546125962', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3528890967705733', 'jcb'));
     $this->assertTrue(Validator::isCreditCard('3337198811307545', 'jcb'));
     $this->assertFalse(Validator::isCreditCard('5020147409985219', 'jcb'));
     /* Maestro (debit card) */
     $this->assertTrue(Validator::isCreditCard('5020147409985219', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020931809905616', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020412965470224', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020129740944022', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020024696747943', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020581514636509', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020695008411987', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('5020565359718977', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('6339931536544062', 'maestro'));
     $this->assertTrue(Validator::isCreditCard('6465028615704406', 'maestro'));
     $this->assertFalse(Validator::isCreditCard('5580424361774366', 'maestro'));
     /* MasterCard */
     $this->assertTrue(Validator::isCreditCard('5580424361774366', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5589563059318282', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5387558333690047', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5163919215247175', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5386742685055055', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5102303335960674', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5526543403964565', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5538725892618432', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5119543573129778', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5391174753915767', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5510994113980714', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5183720260418091', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5488082196086704', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5484645164161834', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5171254350337031', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5526987528136452', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5504148941409358', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5240793507243615', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5162114693017107', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5163104807404753', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5590136167248365', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5565816281038948', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5467639122779531', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5297350261550024', 'mc'));
     $this->assertTrue(Validator::isCreditCard('5162739131368058', 'mc'));
     $this->assertFalse(Validator::isCreditCard('6767432107064987', 'mc'));
     /* Solo 16 */
     $this->assertTrue(Validator::isCreditCard('6767432107064987', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334667758225411', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767037421954068', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767823306394854', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334768185398134', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767286729498589', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334972104431261', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334843427400616', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767493947881311', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767194235798817', 'solo'));
     /* Solo 18 */
     $this->assertTrue(Validator::isCreditCard('676714834398858593', 'solo'));
     $this->assertTrue(Validator::isCreditCard('676751666435130857', 'solo'));
     $this->assertTrue(Validator::isCreditCard('676781908573924236', 'solo'));
     $this->assertTrue(Validator::isCreditCard('633488724644003240', 'solo'));
     $this->assertTrue(Validator::isCreditCard('676732252338067316', 'solo'));
     $this->assertTrue(Validator::isCreditCard('676747520084495821', 'solo'));
     $this->assertTrue(Validator::isCreditCard('633465488901381957', 'solo'));
     $this->assertTrue(Validator::isCreditCard('633487484858610484', 'solo'));
     $this->assertTrue(Validator::isCreditCard('633453764680740694', 'solo'));
     $this->assertTrue(Validator::isCreditCard('676768613295414451', 'solo'));
     /* Solo 19 */
     $this->assertTrue(Validator::isCreditCard('6767838565218340113', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767760119829705181', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767265917091593668', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767938856947440111', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6767501945697390076', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334902868716257379', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334922127686425532', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334933119080706440', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334647959628261714', 'solo'));
     $this->assertTrue(Validator::isCreditCard('6334527312384101382', 'solo'));
     $this->assertFalse(Validator::isCreditCard('5641829171515733', 'solo'));
     /* Switch 16 */
     $this->assertTrue(Validator::isCreditCard('5641829171515733', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641824852820809', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759129648956909', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759626072268156', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641822698388957', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641827123105470', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641823755819553', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641821939587682', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936097148079186', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641829739125009', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641822860725507', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936717688865831', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759487613615441', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641821346840617', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641825793417126', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641821302759595', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759784969918837', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641824910667036', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759139909636173', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333425070638022', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641823910382067', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936295218139423', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333031811316199', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936912044763198', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936387053303824', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759535838760523', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333427174594051', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641829037102700', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641826495463046', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333480852979946', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641827761302876', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641825083505317', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759298096003991', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936119165483420', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936190990500993', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4903356467384927', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333372765092554', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641821330950570', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759841558826118', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936164540922452', 'switch'));
     /* Switch 18 */
     $this->assertTrue(Validator::isCreditCard('493622764224625174', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182823396913535', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675917308304801234', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675919890024220298', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633308376862556751', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182377633208779', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182870014926787', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675979788553829819', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493668394358130935', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493637431790930965', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633321438601941513', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675913800898840986', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182592016841547', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182428380440899', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493696376827623463', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675977939286485757', 'switch'));
     $this->assertTrue(Validator::isCreditCard('490302699502091579', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182085013662230', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493693054263310167', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633321755966697525', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675996851719732811', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493699211208281028', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493697817378356614', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675968224161768150', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493669416873337627', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182439172549714', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675926914467673598', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182565231977809', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675966282607849002', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493691609704348548', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675933118546065120', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493631116677238592', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675921142812825938', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633338311815675113', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633323539867338621', 'switch'));
     $this->assertTrue(Validator::isCreditCard('675964912740845663', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633334008833727504', 'switch'));
     $this->assertTrue(Validator::isCreditCard('493631941273687169', 'switch'));
     $this->assertTrue(Validator::isCreditCard('564182971729706785', 'switch'));
     $this->assertTrue(Validator::isCreditCard('633303461188963496', 'switch'));
     /* Switch 19 */
     $this->assertTrue(Validator::isCreditCard('6759603460617628716', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936705825268647681', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641829846600479183', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759389846573792530', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936189558712637603', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641822217393868189', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4903075563780057152', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936510653566569547', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936503083627303364', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936777334398116272', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641823876900554860', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759619236903407276', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759011470269978117', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333175833997062502', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759498728789080439', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4903020404168157841', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759354334874804313', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759900856420875115', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641827269346868860', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641828995047453870', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333321884754806543', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333108246283715901', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759572372800700102', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4903095096797974933', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333354315797920215', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759163746089433755', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759871666634807647', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641827883728575248', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936527975051407847', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641823318396882141', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759123772311123708', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4903054736148271088', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936477526808883952', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936433964890967966', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6333245128906049344', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936321036970553134', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936111816358702773', 'switch'));
     $this->assertTrue(Validator::isCreditCard('4936196077254804290', 'switch'));
     $this->assertTrue(Validator::isCreditCard('6759558831206830183', 'switch'));
     $this->assertTrue(Validator::isCreditCard('5641827998830403137', 'switch'));
     $this->assertFalse(Validator::isCreditCard('4024007174754', 'switch'));
     /* Visa 13 digit */
     $this->assertTrue(Validator::isCreditCard('4024007174754', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4104816460717', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716229700437', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539305400213', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4728260558665', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929100131792', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007117308', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539915491024', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539790901139', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485284914909', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4782793022350', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556899290685', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007134774', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4333412341316', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539534204543', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485640373626', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929911445746', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539292550806', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716523014030', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007125152', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539758883311', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007103258', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916933155767', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007159672', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716935544871', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929415177779', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929748547896', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929153468612', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539397132104', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485293435540', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485799412720', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916744757686', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556475655426', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539400441625', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485437129173', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716253605320', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539366156589', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916498061392', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716127163779', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007183078', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4041553279654', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532380121960', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485906062491', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539365115149', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485146516702', 'visa'));
     /* Visa 16 digit */
     $this->assertTrue(Validator::isCreditCard('4916375389940009', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929167481032610', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485029969061519', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485573845281759', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485669810383529', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929615806560327', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556807505609535', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532611336232890', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532201952422387', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485073797976290', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007157580969', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4053740470212274', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716265831525676', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007100222966', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539556148303244', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532449879689709', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916805467840986', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532155644440233', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4467977802223781', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539224637000686', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556629187064965', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532970205932943', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4821470132041850', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916214267894485', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4024007169073284', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716783351296122', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556480171913795', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929678411034997', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4682061913519392', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916495481746474', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929007108460499', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539951357838586', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716482691051558', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916385069917516', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929020289494641', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532176245263774', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4556242273553949', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4481007485188614', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4716533372139623', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4929152038152632', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4539404037310550', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4532800925229140', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4916845885268360', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4394514669078434', 'visa'));
     $this->assertTrue(Validator::isCreditCard('4485611378115042', 'visa'));
     $this->assertFalse(Validator::isCreditCard('869940697287073', 'visa'));
     /* Visa Electron */
     $this->assertTrue(Validator::isCreditCard('4175003346287100', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913042516577228', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4917592325659381', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4917084924450511', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4917994610643999', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4175005933743585', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4175008373425044', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913119763664154', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913189017481812', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913085104968622', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4175008803122021', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913294453962489', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4175009797419290', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4175005028142917', 'electron'));
     $this->assertTrue(Validator::isCreditCard('4913940802385364', 'electron'));
     $this->assertFalse(Validator::isCreditCard('869940697287073', 'electron'));
     /* Voyager */
     $this->assertTrue(Validator::isCreditCard('869940697287073', 'voyager'));
     $this->assertTrue(Validator::isCreditCard('869934523596112', 'voyager'));
     $this->assertTrue(Validator::isCreditCard('869958670174621', 'voyager'));
     $this->assertTrue(Validator::isCreditCard('869921250068209', 'voyager'));
     $this->assertTrue(Validator::isCreditCard('869972521242198', 'voyager'));
     $this->assertFalse(Validator::isCreditCard('370482756063980', 'voyager'));
     $this->assertTrue(Validator::isLuhn('869972521242198'));
     $this->assertFalse(Validator::isLuhn(false));
     $this->assertFalse(Validator::isLuhn(null));
     $this->assertFalse(Validator::isLuhn(''));
     $this->assertFalse(Validator::isLuhn(true));
 }
コード例 #2
0
ファイル: Validator.php プロジェクト: nashadalam/lithium
 /**
  * Initializes the list of default validation rules.
  *
  * @return void
  */
 public static function __init()
 {
     $alnum = '[A-Fa-f0-9]';
     $class = get_called_class();
     static::$_methodFilters[$class] = array();
     static::$_rules = array('alphaNumeric' => '/^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{Lt}\\p{Lu}\\p{Nd}]+$/mu', 'blank' => '/[^\\s]/', 'creditCard' => array('amex' => '/^3[4|7]\\d{13}$/', 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/', 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/', 'disc' => '/^(?:6011|650\\d)\\d{12}$/', 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/', 'enroute' => '/^2(?:014|149)\\d{11}$/', 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/', 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/', 'mc' => '/^5[1-5]\\d{14}$/', 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/', 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})' . '\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4]' . '[0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/', 'visa' => '/^4\\d{12}(\\d{3})?$/', 'voyager' => '/^8699[0-9]{11}$/', 'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3' . '(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/'), 'date' => array('dmy' => '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' . '(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?' . '\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?' . '(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])' . '00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|' . '(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%', 'mdy' => '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|' . '1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d' . '{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?' . '(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])' . '00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1' . '\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%', 'ymd' => '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579]' . '[26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)' . '(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|' . '\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])' . '\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]' . '))))$%', 'dMy' => '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)' . '(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ ' . '(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468]' . '[048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|' . 'Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|' . 'Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]' . '\\d)\\d{2})$/', 'Mdy' => '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?' . '|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)' . '|(ne?))|Aug(ust)?|Oct(ober)?|(Sept|Nov|Dec)(ember)?)\\ (0?[1-9]' . '|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ' . '((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468]' . '[048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/', 'My' => '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|' . 'Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)[ /]((1[6-9]' . '|[2-9]\\d)\\d{2})$%', 'my' => '%^(((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9]' . '[0-9][0-9]))))$%'), 'ip' => function ($value, $format = null, array $options = array()) {
         $options += array('flags' => array());
         return (bool) filter_var($value, FILTER_VALIDATE_IP, $options);
     }, 'money' => array('right' => '/^(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))' . '((?!\\1)[,.]\\d{2})?(?<!\\x{00a2})\\p{Sc}?$/u', 'left' => '/^(?!\\x{00a2})\\p{Sc}?(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?' . '(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?$/u'), 'notEmpty' => '/[^\\s]+/m', 'phone' => '/^\\+?[0-9\\(\\)\\-]{10,20}$/', 'postalCode' => '/(^|\\A\\b)[A-Z0-9\\s\\-]{5,}($|\\b\\z)/i', 'regex' => '/^(?:([^[:alpha:]\\\\{<\\[\\(])(.+)(?:\\1))|(?:{(.+)})|(?:<(.+)>)|' . '(?:\\[(.+)\\])|(?:\\((.+)\\))[gimsxu]*$/', 'time' => '%^((0?[1-9]|1[012])(:[0-5]\\d){0,2}([AP]M|[ap]m))$|^([01]\\d|2[0-3])' . '(:[0-5]\\d){0,2}$%', 'boolean' => function ($value) {
         $bool = is_bool($value);
         $filter = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
         return $bool || $filter !== null || empty($value);
     }, 'decimal' => function ($value, $format = null, array $options = array()) {
         if (isset($options['precision'])) {
             $precision = strlen($value) - strrpos($value, '.') - 1;
             if ($precision !== (int) $options['precision']) {
                 return false;
             }
         }
         return filter_var($value, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE) !== null;
     }, 'inList' => function ($value, $format, $options) {
         $options += array('list' => array());
         return in_array($value, $options['list']);
     }, 'lengthBetween' => function ($value, $format, $options) {
         $length = strlen($value);
         $options += array('min' => 1, 'max' => 255);
         return $length >= $options['min'] && $length <= $options['max'];
     }, 'luhn' => function ($value) {
         if (empty($value) || !is_string($value)) {
             return false;
         }
         $sum = 0;
         $length = strlen($value);
         for ($position = 1 - $length % 2; $position < $length; $position += 2) {
             $sum += $value[$position];
         }
         for ($position = $length % 2; $position < $length; $position += 2) {
             $number = $value[$position] * 2;
             $sum += $number < 10 ? $number : $number - 9;
         }
         return $sum % 10 == 0;
     }, 'numeric' => function ($value) {
         return is_numeric($value);
     }, 'inRange' => function ($value, $format, $options) {
         $defaults = array('upper' => null, 'lower' => null);
         $options += $defaults;
         if (!is_numeric($value)) {
             return false;
         }
         switch (true) {
             case !is_null($options['upper']) && !is_null($options['lower']):
                 return $value > $options['lower'] && $value < $options['upper'];
             case !is_null($options['upper']):
                 return $value < $options['upper'];
             case !is_null($options['lower']):
                 return $value > $options['lower'];
         }
         return is_finite($value);
     }, 'uuid' => "/^{$alnum}{8}-{$alnum}{4}-{$alnum}{4}-{$alnum}{4}-{$alnum}{12}\$/", 'email' => function ($value) {
         return filter_var($value, FILTER_VALIDATE_EMAIL);
     }, 'url' => function ($value, $format = null, array $options = array()) {
         $options += array('flags' => array());
         return (bool) filter_var($value, FILTER_VALIDATE_URL, $options);
     });
     $isEmpty = function ($self, $params, $chain) {
         extract($params);
         return empty($value) && $value != '0' ? false : $chain->next($self, $params, $chain);
     };
     static::$_methodFilters[$class]['alphaNumeric'] = array($isEmpty);
     static::$_methodFilters[$class]['notEmpty'] = array($isEmpty);
     static::$_methodFilters[$class]['creditCard'] = array(function ($self, $params, $chain) {
         extract($params);
         $options += array('deep' => false);
         if (strlen($value = str_replace(array('-', ' '), '', $value)) < 13) {
             return false;
         }
         if (!$chain->next($self, compact('value') + $params, $chain)) {
             return false;
         }
         return $options['deep'] ? Validator::isLuhn($value) : true;
     });
     static::$_methodFilters[$class]['email'] = array(function ($self, $params, $chain) {
         extract($params);
         $defaults = array('deep' => false);
         $options += $defaults;
         if (!$chain->next($self, $params, $chain)) {
             return false;
         }
         if (!$options['deep']) {
             return true;
         }
         list($prefix, $host) = explode('@', $params['value']);
         if (getmxrr($host, $mxhosts)) {
             return is_array($mxhosts);
         }
         return false;
     });
 }
コード例 #3
0
 /**
  * Initializes the list of default validation rules.
  *
  * @return void
  */
 public static function __init()
 {
     $alnum = '[A-Fa-f0-9]';
     $class = get_called_class();
     static::$_methodFilters[$class] = array();
     static::$_rules = array('alphaNumeric' => '/^[\\p{Ll}\\p{Lm}\\p{Lo}\\p{Lt}\\p{Lu}\\p{Nd}]+$/mu', 'blank' => '/[^\\s]/', 'creditCard' => array('amex' => '/^3[4|7]\\d{13}$/', 'bankcard' => '/^56(10\\d\\d|022[1-5])\\d{10}$/', 'diners' => '/^(?:3(0[0-5]|[68]\\d)\\d{11})|(?:5[1-5]\\d{14})$/', 'disc' => '/^(?:6011|650\\d)\\d{12}$/', 'electron' => '/^(?:417500|4917\\d{2}|4913\\d{2})\\d{10}$/', 'enroute' => '/^2(?:014|149)\\d{11}$/', 'jcb' => '/^(3\\d{4}|2100|1800)\\d{11}$/', 'maestro' => '/^(?:5020|6\\d{3})\\d{12}$/', 'mc' => '/^5[1-5]\\d{14}$/', 'solo' => '/^(6334[5-9][0-9]|6767[0-9]{2})\\d{10}(\\d{2,3})?$/', 'switch' => '/^(?:49(03(0[2-9]|3[5-9])|11(0[1-2]|7[4-9]|8[1-2])|36[0-9]{2})' . '\\d{10}(\\d{2,3})?)|(?:564182\\d{10}(\\d{2,3})?)|(6(3(33[0-4]' . '[0-9])|759[0-9]{2})\\d{10}(\\d{2,3})?)$/', 'visa' => '/^4\\d{12}(\\d{3})?$/', 'voyager' => '/^8699[0-9]{11}$/', 'fast' => '/^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3' . '(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$/'), 'date' => array('dmy' => '%^(?:(?:31(\\/|-|\\.|\\x20)(?:0?[13578]|1[02]))\\1|(?:(?:29|30)' . '(\\/|-|\\.|\\x20)(?:0?[1,3-9]|1[0-2])\\2))(?:(?:1[6-9]|[2-9]\\d)?' . '\\d{2})$|^(?:29(\\/|-|\\.|\\x20)0?2\\3(?:(?:(?:1[6-9]|[2-9]\\d)?' . '(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])' . '00))))$|^(?:0?[1-9]|1\\d|2[0-8])(\\/|-|\\.|\\x20)(?:(?:0?[1-9])|' . '(?:1[0-2]))\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%', 'mdy' => '%^(?:(?:(?:0?[13578]|1[02])(\\/|-|\\.|\\x20)31)\\1|(?:(?:0?[13-9]|' . '1[0-2])(\\/|-|\\.|\\x20)(?:29|30)\\2))(?:(?:1[6-9]|[2-9]\\d)?\\d' . '{2})$|^(?:0?2(\\/|-|\\.|\\x20)29\\3(?:(?:(?:1[6-9]|[2-9]\\d)?' . '(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])' . '00))))$|^(?:(?:0?[1-9])|(?:1[0-2]))(\\/|-|\\.|\\x20)(?:0?[1-9]|1' . '\\d|2[0-8])\\4(?:(?:1[6-9]|[2-9]\\d)?\\d{2})$%', 'ymd' => '%^(?:(?:(?:(?:(?:1[6-9]|[2-9]\\d)?(?:0[48]|[2468][048]|[13579]' . '[26])|(?:(?:16|[2468][048]|[3579][26])00)))(\\/|-|\\.|\\x20)' . '(?:0?2\\1(?:29)))|(?:(?:(?:1[6-9]|[2-9]\\d)?\\d{2})(\\/|-|\\.|' . '\\x20)(?:(?:(?:0?[13578]|1[02])\\2(?:31))|(?:(?:0?[1,3-9]|1[0-2])' . '\\2(29|30))|(?:(?:0?[1-9])|(?:1[0-2]))\\2(?:0?[1-9]|1\\d|2[0-8]' . '))))$%', 'dMy' => '/^((31(?!\\ (Feb(ruary)?|Apr(il)?|June?|(Sep(?=\\b|t)t?|Nov)' . '(ember)?)))|((30|29)(?!\\ Feb(ruary)?))|(29(?=\\ Feb(ruary)?\\ ' . '(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468]' . '[048]|[3579][26])00)))))|(0?[1-9])|1\\d|2[0-8])\\ (Jan(uary)?|' . 'Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|Aug(ust)?|' . 'Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)\\ ((1[6-9]|[2-9]' . '\\d)\\d{2})$/', 'Mdy' => '/^(?:(((Jan(uary)?|Ma(r(ch)?|y)|Jul(y)?|Aug(ust)?|Oct(ober)?' . '|Dec(ember)?)\\ 31)|((Jan(uary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)' . '|(ne?))|Aug(ust)?|Oct(ober)?|(Sept|Nov|Dec)(ember)?)\\ (0?[1-9]' . '|([12]\\d)|30))|(Feb(ruary)?\\ (0?[1-9]|1\\d|2[0-8]|(29(?=,?\\ ' . '((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468]' . '[048]|[3579][26])00)))))))\\,?\\ ((1[6-9]|[2-9]\\d)\\d{2}))$/', 'My' => '%^(Jan(uary)?|Feb(ruary)?|Ma(r(ch)?|y)|Apr(il)?|Ju((ly?)|(ne?))|' . 'Aug(ust)?|Oct(ober)?|(Sep(?=\\b|t)t?|Nov|Dec)(ember)?)[ /]((1[6-9]' . '|[2-9]\\d)\\d{2})$%', 'my' => '%^(((0[123456789]|10|11|12)([- /.])(([1][9][0-9][0-9])|([2][0-9]' . '[0-9][0-9]))))$%'), 'hostname' => '(?:[a-z0-9][-a-z0-9]*\\.)*(?:[a-z0-9][-a-z0-9]{0,62})\\.' . '(?:(?:[a-z]{2}\\.)?[a-z]{2,4}|museum|travel)', 'ip' => '(?:(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])\\.){3}' . '(?:25[0-5]|2[0-4][0-9]|(?:(?:1[0-9])?|[1-9]?)[0-9])', 'money' => array('right' => '/^(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?(?:\\1\\d{3})*|(?:\\d+))' . '((?!\\1)[,.]\\d{2})?(?<!\\x{00a2})\\p{Sc}?$/u', 'left' => '/^(?!\\x{00a2})\\p{Sc}?(?!0,?\\d)(?:\\d{1,3}(?:([, .])\\d{3})?' . '(?:\\1\\d{3})*|(?:\\d+))((?!\\1)[,.]\\d{2})?$/u'), 'notEmpty' => '/[^\\s]+/m', 'phone' => '/^\\+?[0-9\\(\\)\\-]{10,20}$/', 'postalCode' => '/(^|\\A\\b)[A-Z0-9\\s\\-]{5,}($|\\b\\z)/i', 'regex' => '/^\\/(.+)\\/[gimsxu]*$/', 'time' => '%^((0?[1-9]|1[012])(:[0-5]\\d){0,2}([AP]M|[ap]m))$|^([01]\\d|2[0-3])' . '(:[0-5]\\d){0,2}$%', 'boolean' => function ($value) {
         return in_array($value, array(0, 1, '0', '1', true, false), true);
     }, 'decimal' => function ($value, $format = null, $options = array()) {
         $defaults = array('precision' => null);
         $options += $defaults;
         $precision = '+(?:[eE][-+]?[0-9]+)?';
         $precision = $options['precision'] ? '{' . $options['precision'] . '}' : $precision;
         return (bool) preg_match("/^[-+]?[0-9]*\\.{1}[0-9]{$precision}\$/", (string) $value);
     }, 'inList' => function ($value, $format, $options) {
         $options += array('list' => array());
         return in_array($value, $options['list']);
     }, 'lengthBetween' => function ($value, $format, $options) {
         $length = strlen($value);
         $options += array('min' => 1, 'max' => 255);
         return $length >= $options['min'] && $length <= $options['max'];
     }, 'luhn' => function ($value) {
         if (empty($value) || !is_string($value)) {
             return false;
         }
         $sum = 0;
         $length = strlen($value);
         for ($position = 1 - $length % 2; $position < $length; $position += 2) {
             $sum += $value[$position];
         }
         for ($position = $length % 2; $position < $length; $position += 2) {
             $number = $value[$position] * 2;
             $sum += $number < 10 ? $number : $number - 9;
         }
         return $sum % 10 == 0;
     }, 'numeric' => function ($value) {
         return is_numeric($value);
     }, 'inRange' => function ($value, $format, $options) {
         $defaults = array('upper' => null, 'lower' => null);
         $options += $defaults;
         if (!is_numeric($value)) {
             return false;
         }
         switch (true) {
             case !is_null($options['upper']) && !is_null($options['lower']):
                 return $value > $options['lower'] && $value < $options['upper'];
             case !is_null($options['upper']):
                 return $value < $options['upper'];
             case !is_null($options['lower']):
                 return $value > $options['lower'];
         }
         return is_finite($value);
     }, 'uuid' => "/{$alnum}{8}-{$alnum}{4}-{$alnum}{4}-{$alnum}{4}-{$alnum}{12}/");
     static::$_rules['email'] = '/^[a-z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&\'*+\\/=?^_`';
     static::$_rules['email'] .= '{|}~-]+)*@' . static::$_rules['hostname'] . '$/i';
     $urlChars = '([' . preg_quote('!"$&\'()*+,-.@_:;=') . '\\/0-9a-z]|(%[0-9a-f]{2}))';
     $url = '/^(?:(?:https?|ftps?|file|news|gopher):\\/\\/)__strict__';
     $url .= '(?:' . static::$_rules['ip'] . '|' . static::$_rules['hostname'] . ')';
     $url .= '(?::[1-9][0-9]{0,3})?(?:\\/?|\\/' . $urlChars . '*)?(?:\\?' . $urlChars . '*)?';
     $url .= '(?:#' . $urlChars . '*)?$/i';
     static::$_rules['url'] = array('strict' => str_replace('__strict__', '', $url), 'loose' => str_replace('__strict__', '?', $url));
     $emptyCheck = function ($self, $params, $chain) {
         extract($params);
         return empty($value) && $value != '0' ? false : $chain->next($self, $params, $chain);
     };
     static::$_methodFilters[$class]['alphaNumeric'] = array($emptyCheck);
     static::$_methodFilters[$class]['notEmpty'] = array($emptyCheck);
     static::$_methodFilters[$class]['creditCard'] = array(function ($self, $params, $chain) {
         extract($params);
         $options += array('deep' => false);
         if (strlen($value = str_replace(array('-', ' '), '', $value)) < 13) {
             return false;
         }
         if (!$chain->next($self, compact('value') + $params, $chain)) {
             return false;
         }
         return $options['deep'] ? Validator::isLuhn($value) : true;
     });
     $host = static::$_rules['hostname'];
     static::$_methodFilters[$class]['email'] = array(function ($self, $params, $chain) use($host) {
         extract($params);
         $defaults = array('deep' => false);
         $options += $defaults;
         if (!$chain->next($self, $params, $chain)) {
             return false;
         }
         if (!$options['deep']) {
             return true;
         }
         if (preg_match('/@(' . $host . ')$/i', $value, $regs)) {
             if (getmxrr($regs[1], $mxhosts)) {
                 return is_array($mxhosts);
             }
         }
         return false;
     });
 }