4 digits plus space

I have encountered many requirements: when entering numbers, spaces are required; these should be the most ideal searched on the Internet
var oT = document.getElementById('bno');
oT.oninput = function(ev) {
$("# submitid").addClass("butHui2");
$("#submitid").removeClass("butRed");
var oW = oT.value;
var waybill = document.getElementById('waybill');
oW = oW.replace (/\D+/g, "");
waybill.value = oW;
oT.value = oW;
var oEvent=ev||event;
if(oEvent.keyCode==8)
{
if(oW)
{
for(var i =0;i<oW.length;i++)
{
var newStr=oW.replace(/\s$/g,'');
}
oT.value=newStr;
}
}else{
var t = oW. split("");
var tt = "";
for (var i = 0; i < oW.length; i++) {
tt += t[i];
if ((i + 1) % 4 == 0 && (i + 1) != oW.length) {
tt += " ";
}
}
oT.value = tt;
}


}



每4位加空格;
<input placeholder="请输入12位运单号" id="bno" maxlength="14" onkeyup="this.value =this.value.replace(/\s/g,'').replace(/[^\d]/g,'').replace(/(\d{4})(?=\d)/g,'$1 ');"/>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326391454&siteId=291194637