Re: Regular Expression

From: Date: Tue, 01 Jul 2003 14:02:35 +0000
Subject: Re: Regular Expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-153553@lists.php.net to get a copy of this message
On Tuesday 01 July 2003 21:38, Dan Joseph wrote: > Hi Everyone, > > I am currently using this piece of code to validate wether or not an > address has only letters, numbers, #, or - in it: > > if (!ereg("^[A-Za-z0-9 #-]{1,20}", $_POST["address1"])) { > $error = 1; > $msg .= "Address must only contain letters, numbers, #, or -.<br>"; > } > > However, if I put any valid character as the first, and then any illegal > characters (!@$%, etc) after that, it passes it as ok. Can someone tell me > what I am doing wrong with the regex? You're only checking for valid characters at the *start* of the string, you need to check to the *end* of the string as well: "^[A-Za-z0-9 #-]{1,20}$" ought to do it. -- Jason Wong -> Gremlins Associates -> www.gremlins.biz Open Source Software Systems Integrators * Web Design & Hosting * Internet & Intranet Applications Development * ------------------------------------------ Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general ------------------------------------------ /* "Well, social relevance is a schtick, like mysteries, social relevance, science fiction..." -- Art Spiegelman */

« previous php.general (#153553) next »