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 ([EMAIL PROTECTED], 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 */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php