<input class="in-long" type="text" placeholder="输入标题" id="txt_Title" maxlength="18" onkeyup="this.value =this.value.replace(/\s/g,'').replace(/[^\d]/g,'').replace(/(\d{4})(?=\d)/g,'$1 ');" />
or
<script>
window.onload=function()
{
var oT=document.getElementById('text');
oT.onkeydown=function(ev)
{
var oW=oT.value;
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{
for(var i=0;i<oW.length;i++)
{
var arr=oW.split('');
if((i+1)%5==0)
{
arr.splice(i,0,' ');
}
}
oT.value=arr.join('');
}
}
}
</script>