javascript数据效验类
本文出自 “知识改变命运” 博客
创新互联是专业的琼海网站建设公司,琼海接单;提供成都网站建设、网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行琼海网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
[@more@]/*******************************************
*
num 数字
phone 电话格式
email 电子邮件格式
http 格式
*
num 数字
phone 电话格式
email 电子邮件格式
http 格式
比较时间大小
*/
*/
//浮点数(即小数) ^(-|+)?d+(.d+)?$ // ^[0-9]+(.[0-9]+)?
function check_float(objName)
{
var regExpInfo = /^-?d+$/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
var regExpInfo1 = /^d+.[0-9]{1,3}$/;
if( objName.value.search(regExpInfo1) >= 0 )
{
return true;
}
else
{
alert ("输入内容必须为整数或小数!小数点后最多3位数");
objName.value="";
return false;
}
}
}
function check_float(objName)
{
var regExpInfo = /^-?d+$/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
var regExpInfo1 = /^d+.[0-9]{1,3}$/;
if( objName.value.search(regExpInfo1) >= 0 )
{
return true;
}
else
{
alert ("输入内容必须为整数或小数!小数点后最多3位数");
objName.value="";
return false;
}
}
}
function check_ExNum(objName)
{
var regExpInfo = /^-?d+$/; ///d+/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
return false;
}
}
{
var regExpInfo = /^-?d+$/; ///d+/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
return false;
}
}
//整数
function check_num(objName)
{
var regExpInfo = /^-?d+$/; ///d+/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容必须为整数!");
objName.value="";
return false;
}
}
function check_num(objName)
{
var regExpInfo = /^-?d+$/; ///d+/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容必须为整数!");
objName.value="";
return false;
}
}
//中国电话号码(包括移动和固定电话) (^[0-9]-[0-9]$)│(^[0-9]$)│(^([0-9])[0-9]$)│(^013[0-9]$)
function check_phone(objName)
{
var regExpInfo = /^((d{3,4})|d{3,4}-|s)?d{7,14}$/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的电话号码格式!");
objName.value="";
return false;
}
}
function check_phone(objName)
{
var regExpInfo = /^((d{3,4})|d{3,4}-|s)?d{7,14}$/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的电话号码格式!");
objName.value="";
return false;
}
}
//中国邮政编码
function check_postcode(objName)
{
var regExpInfo = /[1-9]{1}(d+){5}/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的邮政编码格式!");
objName.value="";
return false;
}
}
function check_postcode(objName)
{
var regExpInfo = /[1-9]{1}(d+){5}/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的邮政编码格式!");
objName.value="";
return false;
}
}
//电子邮件
function check_email(objName, obj_Input)
{
var regExpInfo = /(^[w-]+@[w-]+.[A-Za-z0-9]{2,}$)|(^[w-]+@[w-]+.[A-Za-z0-9]+.[A-Za-z0-9]{2,}$)/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的email格式!");
objName.value="";
return false;
}
}
function check_email(objName, obj_Input)
{
var regExpInfo = /(^[w-]+@[w-]+.[A-Za-z0-9]{2,}$)|(^[w-]+@[w-]+.[A-Za-z0-9]+.[A-Za-z0-9]{2,}$)/;
if( objName.value.search(regExpInfo) >= 0 )
{
return true;
}
else
{
alert ("输入内容不是有效的email格式!");
objName.value="";
return false;
}
}
//链接http: /^https?://((w|-)+.)+w+/?$/i
function check_http(objName)
{
var regExpInfo = /http:///;
if( objName.value.search(regExpInfo) == 0)
{
return true;
}
else
{
alert ("输入内容不是有效的链接格式!");
objName.value="";
return false;
}
}
function check_http(objName)
{
var regExpInfo = /http:///;
if( objName.value.search(regExpInfo) == 0)
{
return true;
}
else
{
alert ("输入内容不是有效的链接格式!");
objName.value="";
return false;
}
}
//字母,数字或下划线字符
function check_name(objName)
{
var regExpInfo = /W/;
if( objName.value.search(regExpInfo) >= 0 )
{
alert ("输入内容必须为字母,数字或下划线!");
objName.value="";
return false;
}
else
{
return true;
}
}
function check_name(objName)
{
var regExpInfo = /W/;
if( objName.value.search(regExpInfo) >= 0 )
{
alert ("输入内容必须为字母,数字或下划线!");
objName.value="";
return false;
}
else
{
return true;
}
}
//比较时间大小,
function check_comDate(obj_dateBegain,obj_dateEnd)
{
var dates,datee;
dates = new Date(obj_dateBegain.substr(0,4),obj_dateBegain.substr(5,2),obj_dateBegain.substr(8,2));
datee = new Date(obj_dateEnd.substr(0,4),obj_dateEnd.substr(5,2),obj_dateEnd.substr(8,2));
if( dates <= datee )
{
if( dates == datee )
{
var dates1,datee1
dates1 = new Date(obj_dateBegain.substr(0,4),obj_dateBegain.substr(5,2),obj_dateBegain.substr(8,2),obj_dateBegain.substr(11,2),obj_dateBegain.substr(14,2),obj_dateBegain.substr(17,2));
datee1 = new Date(obj_dateEnd.substr(0,4),obj_dateEnd.substr(5,2),obj_dateEnd.substr(8,2),obj_dateEnd.substr(11,2),obj_dateEnd.substr(14,2),obj_dateEnd.substr(17,2));
if( dates1 <= datee1 )
return true;
else
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
function check_comDate(obj_dateBegain,obj_dateEnd)
{
var dates,datee;
dates = new Date(obj_dateBegain.substr(0,4),obj_dateBegain.substr(5,2),obj_dateBegain.substr(8,2));
datee = new Date(obj_dateEnd.substr(0,4),obj_dateEnd.substr(5,2),obj_dateEnd.substr(8,2));
if( dates <= datee )
{
if( dates == datee )
{
var dates1,datee1
dates1 = new Date(obj_dateBegain.substr(0,4),obj_dateBegain.substr(5,2),obj_dateBegain.substr(8,2),obj_dateBegain.substr(11,2),obj_dateBegain.substr(14,2),obj_dateBegain.substr(17,2));
datee1 = new Date(obj_dateEnd.substr(0,4),obj_dateEnd.substr(5,2),obj_dateEnd.substr(8,2),obj_dateEnd.substr(11,2),obj_dateEnd.substr(14,2),obj_dateEnd.substr(17,2));
if( dates1 <= datee1 )
return true;
else
return false;
}
else
{
return true;
}
}
else
{
return false;
}
}
本文题目:javascript数据效验类
浏览地址:http://lswzjz.com/article/jipsos.html