On 8/2/05, Chris Boget <chris.boget@xxxxxxxx> wrote: > I'm trying to validate an email address and for the life of me I > cannot figure out why the following regex is not working: > > $email = "f.lastname@xxxxxxxxxxxxxxxx"; > $regex = > "^([a-zA-Z0-9_\.\-\']+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-\']+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; [a-zA-Z0-9\-\'] You don't escape hyphens like that in a character class. Put it at the end of the list of characters like this: [a-zA-Z0-9'-] Then it'll match your test address. If you're trying to find out why a regexp isn't working, try simplifying your test cases until it works. For example: $email = "f.lastname@xxxxxxxxxxxxxxxx"; // doesn't work $email = "lastname@xxxxxxxxxxxxxxxx"; // doesn't work $email = "lastname@xxxxxxxxxxxxxx"; // doesn't work $email = "lastname@xxxxxxxxxxx"; // works! I don't suppose this is the place for a rant about the futility of checking email addresses with a regexp? -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php