Re: Validating postal codes

From: Date: Fri, 15 Nov 2002 14:56:10 +0000
Subject: Re: Validating postal codes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-124605@lists.php.net to get a copy of this message
Either you may remove spaces: $form["authpstcode"]=str_replace(' ','',$form["authpstcode"]) and then compare or change your expresion to '(^\s*[a-z]\s*[0-9]\s*[a-z]\s*[0-9]\s*[a-z]\s*[0-9]\s*$)' The first is better as you may put it into database column that is just char(6) DonPro wrote:
Hi, I'm trying to validate a Canadian postal code. I've already written a function; code as follows: if(!eregi('(^[a-z][0-9][a-z][0-9][a-z][0-9]$)',$form["authpstcode"])) { $errors[] = 'You must input a valid Canadian postal code (A9A9A9) postal code if he/she resides in Canada'; $continue = false; } The above works OK if the user enters --> M2M6N6 But fails if the user enters ---> M2M 6N6 (note the space between the two triplets) I want my function to validate either, i.e., allow a space between the two triplets but not enforce it. Any idea on how to modify my test? Thanks, Don


« previous php.general (#124605) next »