js一般的验证
/*
创建时间:2010-09-20
作用:用于一般的验证
注意事项:input中要加入id项;后面的信息显示的div中也要加id项,内容合适为:input的id + ‘Mess’;
*/
var validatedInfo = "<img src='/images/pic_right.gif' width='12' height='12'> ";
var validatedErrorInfo = "<img src='/images/pic_error.gif' width='12' height='12'> ";
var validatedLoadInfo = "<img src='/images/loading.gif' width='12' height='12'> ";
var containsIllegalCharInfo = validatedErrorInfo+"该登陆名由汉字、英文字母或数字组成!";
var checkMessNum = 0;//标示是否有错误,不代表错误信息号
var filterString = "%,&,#,@,!,~,%,&,——,(,),#,@,!";
/**
* 选中下拉框
* @param id
* @param value
* @return
*/
var selected = function(id, value){
$("#"+ id).children().each(function(){
if ($(this).text()== value) this.selected = true;
});
}
/**
* 选中单选项
* @param id
* @param value
* @return
*/
var setRadio = function(name, value){
$("input[@type=radio][@name=" + name + "][@value=" + value + "]").attr("checked", true);
};
/**
* 选中多选项
* @param id
* @param value
* @return
*/
var setCheckbox = function(name, ary){
$("input[@type=checkbox][@name=" + name + "][@value=" + ary + "]").attr("checked", true);
}
/*
var setCheckboxArray = function(name, ary){
$(ary).each(function(i){
$("input[@type=checkbox][@name=" + name + "][@value=" + ary[i] + "]").attr("checked", true);
});
}
*/
/**
* 过滤字符串
* @param {Object} id
* @return {TypeName}
*/
var filterStr = function(id){
var fsAry = filterString.split(",");
var str = "";
for(var i = 0; i < fsAry.length; i++ ) {
if($("#"+ id).val().indexOf(fsAry[i]) != -1) {
str += fsAry[i] + " ";
}
}
return str;
}
/**
* jquery 过滤字符串
* @param {Object} id
* @param {Object} messRight
* @param {Object} messError
* @param {Object} obj
* @return {TypeName}
*/
var jFilterStr = function(id, messRight, messError, obj){
var str = filterStr(id);
if("" != str)
return showMess(id, str + messError, false);
else
return showMess(id, messRight, true);
}
/**
* 验证是否包含空格
*/
var trimBlank = function(id, messRight, messError, obj){
if( obj.value.indexOf(' ') != -1){
return showMess(id, messError, false);
}else{
return showMess(id, messRight, true);
}
};
//验证是否为空
var checkNull = function(id, messRight, messError, obj){
if( $.trim(obj.value) ==''){
return showMess(id, messError, false);
}else{
return showMess(id, messRight, true);
}
};
//验证是否是汉字
var checkMan= function(id, messRight, messError, obj){
var aa=\u4e00-\u9fa5;
if(aa.test($.trim(obj.value))){
return showMess(id, messError, false);
}else{
return showMess(id, messRight, true);
}
};
/**
* 当鼠标点击时,显示的信息
* @param id input中要加入id项
* @param mess 输出的信息
* @param obj
* @author zhangzz
* @return
*/
var checkInfo = function(id, mess, obj){
return showMess(id, '<font color="#A2A2A2">'+mess+'</font>', false);
};
var checkInfoTwo = function(id, mess, obj){
return showMess(id, '<font class="lanhui_sw">'+mess+'</font>', false);
};
//验证最小长度
var checkMinLength = function(id, l, messRight, messError, obj){
/**
* 修改时间:2009年1月20日;修改人:张自忠
* 把一个汉字转换成两个字符
*/
var unlen = obj.value.replace(/[^\x00-\xff]/g, "***").length
if (unlen < l){
return showMess(id, messError, false);
}else{
return showMess(id, messRight, true);