Answer the question
In order to leave comments, you need to log in
How to validate phone number in woocommerce in this case?
I added the following mask to the phone input field on the checkout page
-
jQuery(document).ready(function($){
$("input[name='billing_phone']").mask("+7(000) 000-0000");
});
// Custom validation for Billing Phone checkout field
add_action('woocommerce_checkout_process', 'custom_validate_billing_phone');
function custom_validate_billing_phone() {
$is_correct = preg_match('^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$', $_POST['billing_phone']);
if ($_POST['billing_phone'] && !$is_correct) {
wc_add_notice(__('The Phone field should be <strong>between 6 and 20 digits</strong>.'), 'error');
}
}
Answer the question
In order to leave comments, you need to log in
Try DADATA . He will not only check the phone, but will also provide a lot of help about filling in other fields. There is a plugin for Wordpress, it works fast, via API.
In some cases, it interferes))). But basically - standardizes fillable fields in forms, as expected.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question