kapec gan ne Posted May 1, 2011 Report Share Posted May 1, 2011 kā lai pārbauda personas kodu pareizi?) $code ='010203-12345'; if(preg_match('/^([01-31])+([01-12])+([00-99])*-([00000-99999])$/',$code)) echo 'ok<br/>'; Link to comment Share on other sites More sharing options...
codez Posted May 1, 2011 Report Share Posted May 1, 2011 Personas koda pēdējais cipars ir checksums. Kā to aprēķina, var izlasīt šeit: http://www.feldmans.lv/article/1/ Link to comment Share on other sites More sharing options...
kapec gan ne Posted May 1, 2011 Author Report Share Posted May 1, 2011 domaju bus vieglak ar 2 inputiem un abs(intval()) bet tik precizi man nevajag. galvenais parbaudit pirmos 6 ciparus, lai varetu noteikt dzimsanas dienu. ka tad, lai parbauda tos pirmos 6 ciparus? preg_match('/^([01-31]{2})+([01-12]{2})+([01-99]{2})*-([0-9]{5})+$/',$code) sadi it ka butu ok, vienigi nulles ari akcepte :( Link to comment Share on other sites More sharing options...
daGrevis Posted May 1, 2011 Report Share Posted May 1, 2011 Codez, paldies par rakstu. Bet, nez, vispār ar regulārajām izteiksmēm tas vispār ir izdarāms? Noteikt arī 11 simbolu. Tur jau jātaisa algoritms! Labojums: Un re ku' Tev kaut kas... $pk = '280994-10123'; // Gandrīz vai Mans PK! // Pārbaudām ar regex'u, vai tas ir kaut kas līdzīgs PK. /// ja jā, tad... $pkArray = str_split( $pk ); // Kur $pk ir lietotaja dotais PK. $day = $pkArray[0] . $pkArray[1]; // Ar printf() vari no '01' uz '1' pārtaisīt. $month = $pkArray[2] . $pkArray[3]; switch ( (integer) $pkArray[7] ) { case 0: $century = '18'; break; case 1: $century = '19'; break; case 2: $century = '20'; } $year = $century . $pkArray[4] . $pkArray[5]; echo"{$day}/{$month}/{$year}"; P.S. Kas Tev tieši Tavā "regex'ā" neiet? Link to comment Share on other sites More sharing options...
kapec gan ne Posted May 1, 2011 Author Report Share Posted May 1, 2011 (edited) problema jau ir pasa parbaude... $code ='000000-11111'; preg_match('/^([01-31]{2})+([01-12]{2})+([01-99]{2})*-([0-9]{5})+$/',$code) nezinu kapec, bet 0 vins laiz cauri... noradits it ka ir, ka no 01 tik nem Edited May 1, 2011 by kapec gan ne Link to comment Share on other sites More sharing options...
Rincewind Posted May 1, 2011 Report Share Posted May 1, 2011 (edited) problema jau ir pasa parbaude... $code ='000000-11111'; preg_match('/^([01-31]{2})+([01-12]{2})+([01-99]{2})*-([0-9]{5})+$/',$code) nezinu kapec, bet 0 vins laiz cauri... noradits it ka ir, ka no 01 tik nem Vispār jau [01-31]{2} = [01231]{2} Tā vietā vajag kaut ko līdzīgu [0][1-9]|[1-2][0-9]|[3][0-1] Edited May 1, 2011 by Rincewind Link to comment Share on other sites More sharing options...
Grey_Wolf Posted May 1, 2011 Report Share Posted May 1, 2011 vispar jau ar preg-match NAV iespejams parbudiit vai datums ir Reals piemeram mierigi izies cauri 31 februaris .. ja grib parbaudt tikai relos datumus, tad pratigak ir adalit doto dalju un uzridiit virsu checkdate() Link to comment Share on other sites More sharing options...
Rincewind Posted May 1, 2011 Report Share Posted May 1, 2011 vispar jau ar preg-match NAV iespejams parbudiit vai datums ir Reals 01010001|01020001|01030001|01040001|...|30129999|31129999 :D Bet vispār jau parezi, šito labak ar php checkdate() pārbaudīt. Vai pat vispār nepārbaudīt, tāpat lietotājs ievadīs nepareizu ja gribēs. Kam viņam papildus neērtības? Link to comment Share on other sites More sharing options...
marcis Posted May 2, 2011 Report Share Posted May 2, 2011 Ja runa ir par LV personas kodiem: function validate_pk($pk){ $pk = preg_replace('/\D/', '', $pk); if(strlen($pk) != 11) return false; $calc = 1*$pk[0]+6*$pk[1]+3*$pk[2]+7*$pk[3]+9*$pk[4]+10*$pk[5]+5*$pk[6]+8*$pk[7]+4*$pk[8]+2*$pk[9]; $checksum = (1101-$calc)%11; return $checksum == $pk[10]; } Link to comment Share on other sites More sharing options...
Recommended Posts