admin管理员组文章数量:1417070
I put 10 digit mobile numbers in a Textarea like the follwoing. 242452354643663463636346366363463636365636363634656346 but i need to put ma(,) after every 10 digit number.
I put 10 digit mobile numbers in a Textarea like the follwoing. 242452354643663463636346366363463636365636363634656346 but i need to put ma(,) after every 10 digit number.
Share Improve this question edited Jun 3, 2010 at 6:09 Hari kanna asked Jun 3, 2010 at 6:01 Hari kannaHari kanna 2,5216 gold badges30 silver badges44 bronze badges 2- 1 any example of input and output string? – YOU Commented Jun 3, 2010 at 6:03
- I'm a little unclear if you want to validate that there's a ma after every 10 digits, or insert one automatically – Michael Mrozek Commented Jun 3, 2010 at 6:09
2 Answers
Reset to default 7Like this?
"242452354643663463636346366363463636365636363634656346".replace(/(\d{10})/g,"$1,")
// 2424523546,4366346363,6346366363,4636363656,3636363465,6346
Above solution did not help with splitting a 10 digit phone number being typed into for example a textarea. My solution: 1. your text area should be validated to return only numbers onKeyPress.
then
function mafyPhone(str){
var newStr='';
if(str.length>10){
var str_array=str.split(",");
for(var i = 0; i < str_array.length; i++) {
newStr+=str_array[i].replace(/(\d{10})/g,'$1,');
}
return newStr;
}
return str;
}
On the textarea form field, i used:
onKeyUp="this.value=mafyPhone(this.value);"
However, my solution requires to remove the ma on your last number entered.
本文标签: Input a comma after every 10 digit in JavascriptStack Overflow
版权声明:本文标题:Input a comma after every 10 digit in Javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745259075a2650270.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论