?
<input type="text" name="requestedCorrectionHours" id="correctionInput" value="${wbViewBean.requestedCorrectionHours}"
onblur="leaveToHandler('correctionInput');">
var ERROR_MESSAGE = ({
LIMIT_NUMBER: '<uw:write textKey="label.text.validate.input.limitnumber"/>'
})
?
?????
function leaveToHandler(id){
var value=$("#"+id).val();
if(!verifyData(id,value)){
var obj=$("#"+id);
obj.select();
obj.focus();
setTimeout(function(){obj.focus();obj.select();}, 4000);
}
}
function verifyData(id,data){
var isSuccess = true;
var valueStr=data+"";
var regu = /^[-]?[0-9]+(\.[0-9]+)?$/; //验证带符号和小数点的数字
var patt = new RegExp(regu);
var lengthData = 7; //数字长度,不包括符号
var decimalDigits = 2; //小数点后的位数
if(valueStr.length==0){
$("#"+id).val("0.0");
return isSuccess;
}
if(!patt.test(valueStr)){
showMessage(id,ERROR_MESSAGE.LIMIT_NUMBER);
isSuccess= false;
return isSuccess;
}
var indexStr = valueStr.indexOf('-');
//合法取值是 0 到 stringObject.length - 1,如果要检索的字符串值没有出现,则该方法返回 -1
if(indexStr==0){
valueStr = valueStr.substr(1);
//stringObject.substr(start,length),如果没有指定 lenght,那么返回的字符串包含从 start 到 stringObject 的结尾的字符。
}
if(valueStr.length>lengthData){
showMessage(id,ERROR_MESSAGE.LIMIT_NUMBER);
isSuccess= false;
}else if(valueStr.length<=lengthData){
var index=valueStr.indexOf(".");
if(index>0&&(valueStr.length-index>=(decimalDigits+1))){
showMessage(id,ERROR_MESSAGE.LIMIT_NUMBER);
isSuccess= false;
}
}
return isSuccess;
}
function showMessage(inputId,msg){
msg="<span id='msg_"+inputId+"' class='hint'>"+msg+"</span>";
$("#"+inputId).after(msg);
var msgId="msg_"+inputId;
window.setTimeout("hideMessage('" + msgId + "')",4000);
}
function hideMessage(msgId){
$("#"+msgId).remove();
}
?