//这是一个验证正整数包括小数的JS脚本。求同!//校验输入内容为实数function CheckNewReal(obj){ var parent = obj.parentNode; //清空错误信息,重新校验 clearMassage(obj); var length = 20; var tempValue = obj.value; var patten = /^-?\d+\.?\d*$/; if(tempValue.match(patten) && tempValue.length <= length){ return true; }else if(tempValue.length > length){ var massageObj=document.createElement("div"); massageObj.setAttribute("id","errorMassage"); massageObj.innerHTML="输入的内容不能超过"+length+"个字符"; massageObj.style.color= "red"; parent.insertBefore(massageObj,obj); obj.style.color = "black"; obj.style.border = "1px solid #e50000"; return false; }else if(tempValue.length == 0){ obj.value = "0.0"; }else{ var massageObj=document.createElement("div"); massageObj.setAttribute("id","errorMassage"); massageObj.innerHTML="内容只能为整数或小数"; massageObj.style.color= "red"; parent.insertBefore(massageObj,obj); obj.style.color = "black"; obj.style.border = "1px solid #e50000"; return false; }}
添加回答
举报
0/150
提交
取消