Autor:编辑浪子
From:http://bbs.51js.com/thread-68161-1-1.html
//表单验证类
function ValidatorClass()
{
var IsError = false;
//检查姓名,只能输入中文、字母、数字、下划线
this.ChkName = function(obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<2||(/[^u4e00-u9fa5w]/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查邮件地址
this.ChkEmail = function(obj,msg)
{
if (IsError) return;
if (!/^w+@w+.(?:com|cn|org|net|cc|tv|info|com.cn|net.cn|org.cn|gov.cn)$/i.test(obj.value.Trim())) ErrorHandle(obj,msg);
}
//检查地名,只能是中文,并不能为空
this.ChkPlace = function(obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<1||(/[^u4e00-u9fa5]/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查详细地址
this.ChkAddress = function (obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<2) ErrorHandle(obj,msg);
}
//检查邮件编码
this.ChkPostNumber = function (obj,msg)
{
if (IsError) return;
if(!(/^d{6}$/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查手机号码
this.ChkMobile = function (obj,msg)
{
if (IsError) return;
if (!(/^(?:13d|159)-?d{5}(d{3}|*{3})$/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查固定电话号码
this.ChkPhone = function (obj,msg)
{
if (IsError) return;
if (!((/^d{3,4}-?d{4,5}(d{3}|*{3})$/.test(obj.value.Trim())))) ErrorHandle(obj,msg);
}
//提交表单事件
this.Submit = function (Form,msg)
{
if (IsError) return;
if (msg) alert(msg);
Form.submit();
}
//错误处理
function ErrorHandle(obj,msg)
{
alert(msg);
IsError = true;
obj.focus();
}
}
应用实例:
function ChkForm()
{
var Form = document.TestForm;
var Validator = new ValidatorClass();
Validator.ChkName(Form.ZD_UserName,"订货人姓名不合法!");
Validator.ChkEmail(Form.ZD_Email,"订货人邮件地址不合法!");
Validator.ChkPlace(Form.ZD_Province,"订货人省份不合法!");
Validator.ChkPlace(Form.ZD_City,"订货人城市不合法!");
Validator.ChkAddress(Form.ZD_Address,"订货人地址不合法!");
Validator.ChkPostNumber(Form.ZD_Zip,"订货人邮编不合法!");
Validator.ChkMobile(Form.ZD_Mobile,"订货人移动电话不合法!");
Validator.ChkPhone(Form.ZD_Phone,"订货人固定电话不合法!");
Validator.Submit(Form,"验证成功!");
}
From:http://bbs.51js.com/thread-68161-1-1.html
//表单验证类
function ValidatorClass()
{
var IsError = false;
//检查姓名,只能输入中文、字母、数字、下划线
this.ChkName = function(obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<2||(/[^u4e00-u9fa5w]/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查邮件地址
this.ChkEmail = function(obj,msg)
{
if (IsError) return;
if (!/^w+@w+.(?:com|cn|org|net|cc|tv|info|com.cn|net.cn|org.cn|gov.cn)$/i.test(obj.value.Trim())) ErrorHandle(obj,msg);
}
//检查地名,只能是中文,并不能为空
this.ChkPlace = function(obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<1||(/[^u4e00-u9fa5]/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查详细地址
this.ChkAddress = function (obj,msg)
{
if (IsError) return;
if (obj.value.Trim().length<2) ErrorHandle(obj,msg);
}
//检查邮件编码
this.ChkPostNumber = function (obj,msg)
{
if (IsError) return;
if(!(/^d{6}$/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查手机号码
this.ChkMobile = function (obj,msg)
{
if (IsError) return;
if (!(/^(?:13d|159)-?d{5}(d{3}|*{3})$/.test(obj.value.Trim()))) ErrorHandle(obj,msg);
}
//检查固定电话号码
this.ChkPhone = function (obj,msg)
{
if (IsError) return;
if (!((/^d{3,4}-?d{4,5}(d{3}|*{3})$/.test(obj.value.Trim())))) ErrorHandle(obj,msg);
}
//提交表单事件
this.Submit = function (Form,msg)
{
if (IsError) return;
if (msg) alert(msg);
Form.submit();
}
//错误处理
function ErrorHandle(obj,msg)
{
alert(msg);
IsError = true;
obj.focus();
}
}
应用实例:
function ChkForm()
{
var Form = document.TestForm;
var Validator = new ValidatorClass();
Validator.ChkName(Form.ZD_UserName,"订货人姓名不合法!");
Validator.ChkEmail(Form.ZD_Email,"订货人邮件地址不合法!");
Validator.ChkPlace(Form.ZD_Province,"订货人省份不合法!");
Validator.ChkPlace(Form.ZD_City,"订货人城市不合法!");
Validator.ChkAddress(Form.ZD_Address,"订货人地址不合法!");
Validator.ChkPostNumber(Form.ZD_Zip,"订货人邮编不合法!");
Validator.ChkMobile(Form.ZD_Mobile,"订货人移动电话不合法!");
Validator.ChkPhone(Form.ZD_Phone,"订货人固定电话不合法!");
Validator.Submit(Form,"验证成功!");
}
标签:
编辑浪子版表单验证类
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
桃源资源网 Design By www.nqtax.com
暂无“编辑浪子版表单验证类”评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。