我正在尝试使用Ninja Forms插件找到仅在Wordpress中使用.edu扩展名验证电子邮件的解决方案。
使用Contact Form 7,我可以这样:
function is_edu($email) {
if(substr($email, -4) == '.edu') {
return true;
} else {
return false;
};
};
function custom_email_validation_filter($result, $tag) {
$type = $tag['type'];
$name = $tag['name'];
if($name == 'your-email') { // Only apply to fields with the form field name of "your-email"
$the_value = $_POST[$name];
if(!is_edu($the_value)){
$result['valid'] = false;
$result['reason'][$name] = 'This is not a .edu address!'; // Error message
};
};
return $result;
};
add_filter('wpcf7_validate_email','custom_email_validation_filter', 10, 2); // Email field
add_filter('wpcf7_validate_email*', 'custom_email_validation_filter', 10, 2); // Required Email field
答案 0 :(得分:0)
以下是您可以使用的正则表达式:
if(preg_match('/^[a-zA-z0-9]+@[a-zA-z0-9]+\.edu$/', $emailaddress)) {
//valid email address, start script
}
我想你知道如何在插件中实现它吗?