function email_domain_validation($email){
if (!preg_match('/^([a-z0-9\+\_\-\.]+)@([a-z0-9\+\_\-\.]{2,})(\.[a-z]{2,4})$/i', $email)) return false;
$domains = array('mail.ru','op.ru','mail.ro','op.ro','mail.pl','op.pl');
list(, $email_domain) = explode('@', $email, 2);
return in_array($email_domain, $domains);
}
add_filter('cred_form_validate','func_email_validation',10,2);
function func_email_validation($error_fields, $form_data){
list($fields,$errors)=$error_fields;
if ($form_data['id']==791){ // id of email post-form
$is_unvalid_email_domain = email_domain_validation($_POST['wpcf-guest_email']);
if($is_unvalid_email_domain) {
$errors['wpcf-guest_email']='Dit e-mailadres is niet toegestaan.';
}
//check hidden_field value
if ($fields['wpcf-hidden_field']['value']!='') {
//set error message for hidden_field
$errors['hidden_field']='We hebben je gevangen, jij stiekemerd!';
}
// check guest_phone has 10 digits and starting with 06
if ($fields['wpcf-guest_phone']['value']!=preg_match('/^(?:06)\d{10}$') ) {
//set error message for guest_phone
$errors['guest_phone']='Geef een correct mobiel nummer';
}
}
return array($fields,$errors);
}
I would like to get assistance in making this part below with 'preg_match' work.
// check guest_phone has 10 digits and starting with 06
if ($fields['wpcf-guest_phone']['value']!=preg_match('/^(?:06)\d{10}$') ) {
//set error message for guest_phone
$errors['guest_phone']='Geef een correct mobiel nummer';
}