如何在Wordpress联系人表单7插件中创建自定义手机号码验证是可能的,请帮助我。实际上,我只想有效的手机号码是允许此字段不采取任何其他字符的ex- 9708644571
发布于 2017-04-26 13:51:33
要使用电话号码验证,您需要按照下面给出的示例放入number字段。
[number* your-number min:9 max:10 step:3 class:required "40"]参考链接:CF7
发布于 2017-04-26 14:18:53
如果您想对手机号码使用自定义验证,那么您也可以使用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替换为您的输入字段包装类,或者您可以根据需要修改您的类和输入名称。
希望,这可能对你有帮助。
发布于 2018-03-29 13:33:29
// 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 );https://stackoverflow.com/questions/43625800
复制相似问题