我想在特定输入上有一个输入掩码,它将用户输入解析为人类可读的美国电话号码。
例如
用户输入:1231231234 用户查看:(123)-123-1234
到目前为止我所做的是,我做了一个像下面这样的手表方法
switch (this.form.values.primary_phone.length) {
case 3:
return this.form.values.primary_phone = this.form.values.primary_phone.replace(/^([0-9]{3})$/, '($1)');
case 6:
return this.form.values.primary_phone = this.form.values.primary_phone.replace(/^([0-9]{3})([0-9]{3})$/, '($1)-$2');
case 10:
return this.form.values.primary_phone = this.form.values.primary_phone.replace(/^([0-9]{3})([0-9]{3})([0-9]{4})$/, '($1)-$2-$3');
}
Run Code Online (Sandbox Code Playgroud)
现在,只有当我从输入中聚焦时才会更新值。有没有办法在输入仍处于焦点时进行更新?
vue.js ×1