NBS Posted January 27, 2009 Report Share Posted January 27, 2009 Sveiki, man ir šāds, piemērs, ko man palūdza pārveidot, bet man ne jausmas, kā viņš īsti un ko pārbauda. Sekojoši kods ir šīs: d0128 = '([012][1-8]|[01]9|[12]0)(0\\d|1[012])\\d{2}'; d3031 = '3(0(0[13-9]|1[012])|1(0[13578]|1[02]))\\d{2}'; d29 = '29(02([02468][048]|[13579][26])|(0[13-9]|1[012])\\d{2})'; reg = new RegExp('^(('+ d0128 +')|('+ d3031 +')|('+ d29 +'))-[01]\\d{4}$'); Vai kāds man varētu, lūdzu, iztulkot, ko pārbauda d29, d3031, d0128. Es būtu ļoti pateicīgs, paldies. Link to comment Share on other sites More sharing options...
bubu Posted January 27, 2009 Report Share Posted January 27, 2009 hm, toč izskatās kā pēc manis raksīta regexpa personas koda pārbaudei gadus 6 atpakaļ: http://home.lanet.lv/~sd10104/tt1/md7.html <script> // datumi kuros ir 01 liidz 28 datums var datums0128 = "([012][1-8]|[01]9|[12]0)(0\\d|1[012])\\d{2}"; // datumi kuros ir 30 liidz 31 datums var datums3031 = "3(0(0[13-9]|1[012])|1(0[13578]|1[02]))\\d{2}"; // datumi kuros ir 29 datums var datums29 = "29(02([02468][048]|[13579][26])|(0[13-9]|1[012])\\d{2})"; // saliekam visu kopaa var regularPK = new RegExp("^((" + datums0128 + ")|(" + datums3031 + ")|(" + datums29 + "))-[12]\\d{4}$"); Link to comment Share on other sites More sharing options...
NBS Posted January 27, 2009 Author Report Share Posted January 27, 2009 Lūdzu nevajag taisīt bezjēdzīgas QUOTEs Liels paldies, nezinu vai esi to rakstījis vai nē, bet vismaz es točna neesmu. Ņja, izrādās man tas RegExp pat īsti nav vajadzīgs, jo vajag pārbaudīt personas kodu. Neredzu nekādu sakarību ar šo RegExp. Link to comment Share on other sites More sharing options...
rpr Posted January 28, 2009 Report Share Posted January 28, 2009 /** * check persons code * @var cPcode string LV citizen person's code * @return boolean */ function PCodeCheck($cPCode) { $cPCode = str_replace("-", "", $cPCode); if (!preg_match("/^\d{11}$/", $cPCode)) return false; $nCheckSum = 0; $aCheck = array(1, 6, 3, 7, 9, 10, 5, 8, 4, 2); for ($i=0; $i<10; $i++ ) { $nCheckSum += intval($cPCode[$i]) * $aCheck[$i]; } return ((1101 - $nCheckSum) % 11)==substr($cPCode, -1); } Link to comment Share on other sites More sharing options...
bubu Posted January 28, 2009 Report Share Posted January 28, 2009 Aha, un tavs kods personas kodu 222222-22221 uzskatīs par pareizu. Veiksmi atrast kādu, kurš dzimis 22. mēnesī :) Link to comment Share on other sites More sharing options...
Recommended Posts