如何在联系表 7 中进行手机号码验证?
How to make mobile number validation in contact form 7?
如何在 Wordpress 联系表单 7 插件中创建自定义手机号码验证是否可行请帮助我。
实际上我只想允许有效的手机号码这个字段不带任何其他字符 ex- 9708644571
要使用 phone 数字验证,您需要按照下面给出的示例放置数字字段。
[number* your-number min:9 max:10 step:3 class:required "40"]
参考 link : CF7
如果您想对手机号码使用自定义验证,那么您也可以使用jQuery。
就像这样:
$('.wpcf7-form .custom-field-class input').on('keypress', function(e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 43 || e.which > 57)) {
return false;
}
});
将此文件放在存在表单的页面模板中或 footer.php 或自定义 js 文件中。
请将 custom-field-class
替换为您的输入字段包装 class 或者您可以根据您的要求修改 classes & inputs 名称。
希望这对您有所帮助。
// Phone number validation : format and 10 digits
// Add code in your functions.php file
function custom_contact_validation_filter( $result, $tag ) {
// 'contact': is name of tag in contact form
if ( 'contact' == $tag->name ) {
$re_format = '/^[0-9]{10}+$/'; //9425786311
$your_contact = $_POST['contact'];
if (!preg_match($re_format, $your_contact , $matches)) {
$result->invalidate($tag, "Enter 10 digits only" );
}
}
return $result;
}
add_filter( 'wpcf7_validate_text*', 'custom_contact_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text', 'custom_contact_validation_filter', 10, 2 );
如何在 Wordpress 联系表单 7 插件中创建自定义手机号码验证是否可行请帮助我。 实际上我只想允许有效的手机号码这个字段不带任何其他字符 ex- 9708644571
要使用 phone 数字验证,您需要按照下面给出的示例放置数字字段。
[number* your-number min:9 max:10 step:3 class:required "40"]
参考 link : CF7
如果您想对手机号码使用自定义验证,那么您也可以使用jQuery。
就像这样:
$('.wpcf7-form .custom-field-class input').on('keypress', function(e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 43 || e.which > 57)) {
return false;
}
});
将此文件放在存在表单的页面模板中或 footer.php 或自定义 js 文件中。
请将 custom-field-class
替换为您的输入字段包装 class 或者您可以根据您的要求修改 classes & inputs 名称。
希望这对您有所帮助。
// Phone number validation : format and 10 digits
// Add code in your functions.php file
function custom_contact_validation_filter( $result, $tag ) {
// 'contact': is name of tag in contact form
if ( 'contact' == $tag->name ) {
$re_format = '/^[0-9]{10}+$/'; //9425786311
$your_contact = $_POST['contact'];
if (!preg_match($re_format, $your_contact , $matches)) {
$result->invalidate($tag, "Enter 10 digits only" );
}
}
return $result;
}
add_filter( 'wpcf7_validate_text*', 'custom_contact_validation_filter', 10, 2 );
add_filter( 'wpcf7_validate_text', 'custom_contact_validation_filter', 10, 2 );