This article mainly introduces the example of Vue implementing the segmentation of mobile phone numbers in the number input box. The editor thinks it is quite good, so I will share it with you now and give it as a reference. Let’s follow the editor to take a look, I hope it can help everyone.
Requirements
When the system numeric keyboard pops up on the mobile terminal and the mobile phone number is entered, use the 344 format to split it.
Analysis:
First of all, if you want to pop up the numeric keyboard on the mobile terminal and there can be spaces, then you must use type=" phone" input box
If you want to increase spaces when inputting and reduce spaces when deleting, then you must use watch
mobile phone The number is 11 digits, plus two spaces, up to 13 digits, so the length must be limited
Code implementation
##
<body> <p id="app"> <!-- 类型为phone,最大长度为13 --> <input type="phone" v-model="dataPhone" maxlength="13"> </p> </body> <script> var vm = new Vue({ el: '#app', data() { return { dataPhone: '' } }, watch: { // 通过watch来设置空格 dataPhone(newValue, oldValue) { if (newValue.length > oldValue.length) { // 文本框中输入 if (newValue.length === 3 || newValue.length === 8) { this.dataPhone += ' ' } } else { // 文本框中删除 if (newValue.length === 9 || newValue.length === 4) { this.dataPhone = this.dataPhone.trim() } } } } }) </script>
vue implements mobile phone number lottery up and down scrolling animation example sharing
AngularJS implements form verification mobile phone number function
Recommended articles about mobile phone numbers
The above is the detailed content of Tutorial on how to use Vue to split mobile phone numbers in digital input boxes. For more information, please follow other related articles on the PHP Chinese website!