^ is only NOT when it's the first character within brackets, [ and ]. Also, don't escape the $ at the end if you really want it to match the end of the string. Right now your regular expression is matching a literal dollar sign.
As for the original question, it looks correct, providing you can have those swedish characters in the brackets. What if you just simplify things and make your ereg look to match a single one of those swedish chacters? Will it validate correctly if that's all you pass? Play with taking them in and out and see what works. ---John Holmes... ----- Original Message ----- From: "Wico de Leeuw" <[EMAIL PROTECTED]> To: "Anders Thoresson" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Wednesday, December 18, 2002 11:26 AM Subject: Re: [PHP] ereg. ^ is not in this case Try if(!ereg("^([a-zA-ZåÅäÄöÖ]{4,20})\$", $_REQUEST['f_name'])) { Added the $ at the end else the could be more then 20 chars Greetz At 17:20 18-12-02 +0100, Anders Thoresson wrote: >What's wrong with the following regular expression? As far as I can se, >only alphabetic characters including the special swedish ones, should be >let through, but whatever character passed on in $_REQUEST['f_name'] >passes the test? > > if(!ereg("(^[a-zA-ZåÅäÄöÖ]{4,20})", $_REQUEST['f_name'])) { > error("Your first name should be between 4 and 20 > alphabetic characters"); > } > >The next one, used to check valid birthday dates, work. And I can't see >where they differ! > > if(!ereg("([0-9]{4})-([0-9]{2})-([0-9]{2})", $_REQUEST['birthday'])) > >Br, > > Anders > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php