如何在###-####-###中设置联系表格7电话号码格式 [英] How to set the contact form 7 phone number format in ###-####-###
问题描述
我使用的是联系方式7,我想知道当用户输入的电话号码格式为###-#####-###时,是否可以设置电话号码,默认情况下,请提前感谢
I am using contact form 7,I was wondering is there a way to set the Phone number when Put by the user is the format ###-####-###,By default, Thanks in advance
推荐答案
更新2019,因为将不会更新Masked Input插件:
Update 2019, since Masked Input Plugin will not be updated:
请按照以下步骤操作:
1)下载 Cleave.js ;
2)打开您的主题javascript文件夹(例如,Twenty 17),然后将该文件放入wp-content/themes/twentyseventeen/js;
2) Open your theme javascript folder (for example, Twenty Seventeen) and put the file in wp-content/themes/twentyseventeen/js;
3)打开functions.php文件(位于主题的根文件夹中),然后将代码粘贴到其底部:
3) Open the functions.php file (located in root folder of your theme) and paste the code in the botton of it:
//Enqueue Cleave.js
function enqueue_cleave(){
wp_enqueue_script('cleave', get_stylesheet_directory_uri().'/js/cleave.min.js');
}
add_action('wp_enqueue_scripts', 'enqueue_cleave');
add_action('wp_footer', 'activate_cleave');
function activate_cleave(){
if( is_page('contact') ){ //only contact page will load the script.
?>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', () => {
var phone = new Cleave('#phone', {
numericOnly:true,
delimiter:'-',
blocks:[3,4,3]
});
});
</script>
<?php
}
}
5)在联系表7中创建一个输入字段(id:phone将用于Cleave.js):
5) Create an input field in Contact Form 7 (id:phone will be used for Cleave.js):
[text phone id:phone placeholder "Your phone number here."]
6)创建一个名为"contact"的页面,并将表单放入其中.
6) Create a page with the name 'contact' and put your form in it.
就是这样.
这篇关于如何在###-####-###中设置联系表格7电话号码格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!