PHP: Email validation and accepting email address from a certain domain
<p>I am currently working with AJAX/JS to have form without a button click or page refresh. The inquiry I have is in regards of email validation. Right now the PHP code checks if an email address is valid or not. I would like to only have it accept emails from a certain domain. How can I achieve through php to accept only email address from <code>gmail</code>? <a href="http://webprolearner.ueuo.com/dropdown-menu/test1.php" rel="nofollow"><strong>Example</strong></a></p>

<p><strong>PHP for validation of email:</strong></p>

<pre><code>if($_POST) {
    $email = $_POST['email'];
    if (preg_match('|^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$|i', $email)) {
        echo ('&lt;div id="email_input"&gt;&lt;span id="resultval"&gt;'.$email.'&lt;/span&gt;&lt;/div&gt;');
    }
    else {
        echo ('&lt;div id="email_input"&gt;&lt;span id="resultval"&gt;Include a valid email address.&lt;/span&gt;&lt;/div&gt;');
    }
}
</code></pre>
