Possible Duplicate:
telephone number format with jquery®ex
我需要验证并将任何输入值转换为电话号码格式,即
输入er + f375g25123435s67我需要转换为+375 25 1234567
最合适的代码是:
$('input').live({
keyup: function(){
ipt = $(this).val().replace(/[^\d]*/g, "");
// remove non-digits
ipt = "+" + ipt.substring(0, 3) + " " + ipt.substring(4, 6) + " " + ipt.substring(7, 14);
$(this).val(ipt);
}
});
+375
之后输入数字+375
之后启用数字ipt.substring(0, 3) + " " + ipt.substring(4, 6) + " " + ipt.substring(7, 14)
转换为正则表达式?最佳答案
您可能需要查看以下内容:http://digitalbush.com/projects/masked-input-plugin/