Saatana
Saatana

Reputation: 1167

Validate email with certain domain with regular expressions

I've been playing around with this expression for an hour now and I can't seem to get it to work. I need to validate an email with a certain domain. The email must be in the format:

[email protected]

The domain could be either .ca .com or .org and the first and last name must be between 4 and 10 characters. This is the code I have right now

/^[a-z]{4,10}\.[a-z]{4,10}[@]abc\.(com|ca|org)$/i

Can anyone see what I've done wrong? Thank you in advance!

Upvotes: 1

Views: 785

Answers (1)

Martin Lyne
Martin Lyne

Reputation: 3065

If you are seeking to validate an email address it is already handled sufficiently by using

filter_var('[email protected]', FILTER_VALIDATE_EMAIL)

Manual: http://php.net/manual/en/function.filter-var.php

Upvotes: 3

Related Questions