在自动完成的电话号码中添加破折号 [英] Add dash in auto complete phone number

查看:90
本文介绍了在自动完成的电话号码中添加破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

是否可以在自动完成中自动添加破折号-"?

Is it possible to automatically add a dash "-" in auto complete?

假设我有一个电话号码字段,如果有人在其中键入他们的电话号码,则会显示浏览器自动完成功能.

Let say I have a phone number field and if someone will type their phone number in it the browser auto complete will show.

例如

这是浏览器的自动完成值 1234567890

This is the browser auto complete value 1234567890

一旦他们选择我要自动将其设置为此格式

Once they select that I want to automatically format it to this

123-456-7890

123-456-7890

因为有些网站的电话字段中没有验证格式,所以您可以连续输入10位数字,并且一旦在浏览器缓存中将其输入,它也将显示在其他电话字段中.

Because there are some site that they dont have a validation format into their phone field you can input 10 digit number continuesly and once you have that in your browser cache it will also display into other phone field.

谢谢.

推荐答案

$('#phone-number-field').keyup(function(){
    $(this).val($(this).val().replace(/(\d{3})\-?(\d{3})\-?(\d{4})/,'$1-$2-$3'))
});

这篇关于在自动完成的电话号码中添加破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆