cvs: pear /Validate/Validate AT.php

From: Date: Wed, 10 Dec 2003 16:19:25 +0000
Subject: cvs: pear /Validate/Validate AT.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-14766@lists.php.net to get a copy of this message
mike Wed Dec 10 11:19:25 2003 EDT Modified files: /pear/Validate/Validate AT.php Log: - rewrote postcode validation - stripped some chars from the ssn pcre Index: pear/Validate/Validate/AT.php diff -u pear/Validate/Validate/AT.php:1.2 pear/Validate/Validate/AT.php:1.3 --- pear/Validate/Validate/AT.php:1.2 Wed Dec 10 10:07:34 2003 +++ pear/Validate/Validate/AT.php Wed Dec 10 11:19:25 2003 @@ -15,7 +15,7 @@ // | Copyright (c) 2003 Michael Wallner <mike@iworks.at> | // +----------------------------------------------------------------------+ // -// $Id: AT.php,v 1.2 2003/12/10 15:07:34 pajoye Exp $ +// $Id: AT.php,v 1.3 2003/12/10 16:19:25 mike Exp $ /** * Requires Validate @@ -29,7 +29,7 @@ * @package Validate * @category PHP * -* @version $Revision: 1.2 $ +* @version $Revision: 1.3 $ * @access public */ class Validate_AT @@ -46,8 +46,14 @@ */ function postcode($zip) { - $zip = (int) $zip; - return ($zip < 9992 && $zip > 1009); + static $postcodes; + + if (!isset($postcodes)) { + $file = '@DATADIR@/Validate/AT_postcodes.txt'; + $postcodes = array_map('trim', file($file)); + } + + return in_array((int) $zip, $postcodes); } /** @@ -63,7 +69,7 @@ function ssn($svn) { $matched = preg_match( - '/^(\d{3})(\d)[\D]*(\d{2})[\D]*(\d{2})[\D]*(\d{2})$/', + '/^(\d{3})(\d)\D*(\d{2})\D*(\d{2})\D*(\d{2})$/', $svn, $matches ); @@ -71,27 +77,27 @@ if (!$matched) { return false; } - + list(, $num, $chk, $d, $m, $y) = $matches; if (!Validate::date("$d-$m-$y", array('format' => '%d-%m-%y'))) { return false; } - + $str = (string) $num . $chk . $d . $m . $y; $len = strlen($str); $fkt = '3790584216'; $sum = 0; - + for ($i = 0; $i < $len; $i++) { $sum += $str{$i} * $fkt{$i}; } - + $sum = $sum % 11; if ($sum == 10) { $sum = 0; } - + return ($sum == $chk); } }

« previous php.pear.cvs (#14766) next »