Mobile phone number input box, set to 6005 1078 to automatically add spaces
question: [when you need to modify the number (6005), the cursor will jump to the end of the number immediately after deleting the number]
demand: [after deleting the number, the cursor will not jump to the end and can be modified normally]
ask colleagues, teachers, God to help me, this bug has been hanging with me for a long time. Thank you!
code is as follows
return function (input, space) {
if (!input) {
return ""
}
space = space || " "
input = input.replace(/\s+/g, "") //
var valArry = input.split("")
if (valArry.length > 7) {
valArry = valArry.splice(7, 0, space)
}
if (valArry.length > 3) {
valArry = valArry.splice(3, 0, space)
}
return valArry.join("");
}
I triggered it with the keyup event