以下代码:input验证码框,输入非数字或非12位时,红框提示;每4位加一个空格
//input验证码框,输入非数字或非12位时,红框提示;每3位加一个空格$(".text").focus(function(){$(this).keyup(function(){var num = /^[0-9]*$/;var verifyValue = $(this).val();var deleteLogo = $(".delete-logo");//删除的小叉号verifyValue=verifyValue.replace(/\s+/g,"");//清掉空格if(verifyValue.length > 9){verifyValue = verifyValue.substring(0,9);//只允许输入9位数}if(!num.test(verifyValue)||verifyValue.length!=9){$(".text").css("border","1px solid #ff661b");//输入非数字,或非9位数,input边框显示红色}else{$(".text").css("border","1px solid #cecece");}if(num.test(verifyValue)&&verifyValue.length==9){$(".verify").css("background","#ff661b");//输入符合要求,下一步按钮显示亮色}else{$(".verify").css("background","#a9a9a9");}verifyValue = verifyValue.replace(/(.{3})/g,"$1 ").replace(/\s+$/g,"");//每输入3位数,添加一个空格。$(this).val(verifyValue);if(verifyValue.length > 0){deleteLogo.show();//输入不为空时,显示右边的小叉号}else{deleteLogo.hide();}});});