Regular Expression (PHP)

Associate
Joined
14 Oct 2008
Posts
416
I'm trying to add a regular expression to a registration page I've done in PHP but I'm absolutely useless with them! Anyone able to help?

I only want people to be able to register with an email from a specific university...

So I need a regular expression to check, for example, that the email address ends with @dmu.ac.uk

I thought I'd try my luck with: preg_match("@dmu.ac.uk$", $pEmail) just to test it but just got an error (unsurprisingly). Guesswork doesn't often work with regular expressions :(

Any help would be appreciated.

Thanks in advance.
 
Last edited:
It needs to be

PHP:
if (preg_match("/@dmu\.ac\.uk$/", $checkThis)) {
}

That should work :) The dot is a special char in reg exps so needs escaping....you should probably also validate the bit before the @ sign to make sure it's only valid characters allowed in there.
 
Last edited:
It needs to be

PHP:
if (preg_match("/@dmu\.ac\.uk$/", $checkThis)) {
}

That should work :) The dot is a special char in reg exps so needs escaping....you should probably also validate the bit before the @ sign to make sure it's only valid characters allowed in there.
Perfect, it worked. Thanks :)

Yeah, I've done that already with this huge function I found!
http://www.iamcal.com/publish/articles/php/parsing_email

No need to use a regexp for that - strpos will be faster :)
Doh! Just put the regular expression in. I'll have a look into that too, thanks.
 
Back
Top Bottom