有人可以帮助我吗? 即,我想为注册中的“电话”字段设置字符长度,如果超过10个字符,则显示错误。
表格: enter image description here
通过这种方式,我已经可以从“电话”字段中获取值:
/themes/functions.php
add_action('woocommerce_created_customer', 'handle_created_customer', 10, 3);
function handle_created_customer($customer_id, $new_customer_data, $password_generated) {
$fName = htmlspecialchars(strip_tags($_POST['wpuef_options']['c11']));
$lName = htmlspecialchars(strip_tags($_POST['wpuef_options']['c15']));
$street = htmlspecialchars(strip_tags($_POST['wpuef_options']['c23']));
$pCode = htmlspecialchars(strip_tags($_POST['wpuef_options']['c31']));
$city = htmlspecialchars(strip_tags($_POST['wpuef_options']['c35']));
$phone = htmlspecialchars(strip_tags($_POST['wpuef_options']['c43']));
sendXMLData($new_customer_data['user_email'], $fName, $lName, $phone, $city, $street, $pCode);
}
是否可以在同一个文件中设置一个新功能来检查 $ phone> 10个字符以显示错误。
希望您能理解我的问题,谢谢大家的帮助
答案 0 :(得分:0)
您可以使用PHP的strlen()函数获取字符串的长度。
$phoneNumberLength = strlen((string)$phone);
将为您提供电话号码中的字符数。