javascript 表单规则集合对象

2022-10-18,,,,

复制代码 代码如下:
<script type="text/javascript">
//更多的验证可以继续添加到errmsg对象
var errmsg={
required:{
msg:"this field is required.",
//load参数指定是否在加载的时候验证
test:function(obj,load){
return obj.value.length > 0 || load || obj.value==obj.defaultvalue;
}
},
//验证邮件
email:{
meg:"not a valid email address.",
test:function(obj){
return /^[a-z0-9a-z+_.-]+\@([a-z0-9a-z-_]+\.)+[a-z0-9]{2,4}$/i.test(obj.value);
}
},
//验证网址
url:{
msg:"not a valid url.",
test:function(obj){
return obj.value=="http://" || /^https?:\/\/([a-z0-9-]+\.)+[a-z0-9]{2,4}.*$/.test(obj.value);
}
}
}
//example
onload=function(){
$("url").onblur=function(){
if(errmsg.url.test(this)){
alert("right");
}else{
alert(errmsg.url.msg);
}
}
}
</script>

《javascript 表单规则集合对象.doc》

下载本文的Word格式文档,以方便收藏与打印。