如何在从“05”开始的 woocommerce 结帐页面中创建验证 phone 号码
How can I create Validate phone number in woocommerce checkout page that starts from "05"
如何在从“05”开始的 woocommerce 结帐页面中创建验证 phone 号码。并且最多应为 10 位数字。但是,Space 不应包含在这 10 位数字中。
我有答案并且有效:
// Limit Woocommerce phone field to 10 digits number || Mdsourov || sourov.com
add_action('woocommerce_checkout_process', 'njengah_custom_checkout_field_process');
function njengah_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error. This one is only requite for companies
$is_correct = preg_match('/^05[0-9]{8}$/', $_POST['billing_phone']);
if ( $_POST['billing_phone'] && !$is_correct) {
wc_add_notice( "Incorrect Phone Number! Please enter valid 10 digits phone number that start with 05" ,'error' );
}
}
如何在从“05”开始的 woocommerce 结帐页面中创建验证 phone 号码。并且最多应为 10 位数字。但是,Space 不应包含在这 10 位数字中。
我有答案并且有效:
// Limit Woocommerce phone field to 10 digits number || Mdsourov || sourov.com
add_action('woocommerce_checkout_process', 'njengah_custom_checkout_field_process');
function njengah_custom_checkout_field_process() {
global $woocommerce;
// Check if set, if its not set add an error. This one is only requite for companies
$is_correct = preg_match('/^05[0-9]{8}$/', $_POST['billing_phone']);
if ( $_POST['billing_phone'] && !$is_correct) {
wc_add_notice( "Incorrect Phone Number! Please enter valid 10 digits phone number that start with 05" ,'error' );
}
}