php - Validate email and ban certain domains

943

I have this code I currently use to validate emails:

return (bool) preg_match('/^([a-z0-9\+\_\-\.]+)@([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $arg0);

How can I modify that code so I can ban several domains? I don't want any extra files to add, just to modify this code.

Thank you.

235

Answer

Solution:

The easiest way would be to have an array with banned providers:

$providers = Array ( 'gmail.com', 'yahoo.com' );

and then just loop trough that array and check if provided email contains'@' . $provider.

People are also looking for solutions to the problem: Post 1:N (one customer many phonenumbers) JSON Array to android and parse it in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.