· 9 years ago · Jan 30, 2017, 10:52 PM
1jQuery(document).ready(function($) {
2 $('#registerform').find(':submit').click(function(e) {
3 if( ! isGmail( $('#user_email').val() ) ) {
4 e.preventDefault(); // Prevent the form from submitting
5 alert('You can only register with an @gmail.com email address!');
6 return false;
7 }
8 });
9});
10
11function isGmail( address ) {
12 return address.indexOf("@gmail.com", this.length - 10) !== -1;
13}
14
15function is_valid_email_domain($login, $email, $errors ){
16 $valid_email_domains = array("gmail.com","yahoo.com");// whitelist
17 $valid = false;
18 foreach( $valid_email_domains as $d ){
19 $d_length = strlen( $d );
20 $current_email_domain = strtolower( substr( $email, -($d_length), $d_length));
21 if( $current_email_domain == strtolower($d) ){
22 $valid = true;
23 break;
24 }
25 }
26 // if invalid, return error
27 if( $valid === false ){
28 $errors->add('domain_whitelist_error',__( '<strong>ERROR</strong>: you can only register using gmail or yahoo emails' ));
29 }
30}
31
32add_action('register_post', 'is_valid_email_domain',10,3 );