表单验证验证表单基本验证功能Word文档下载推荐.docx

上传人:b****3 文档编号:17234517 上传时间:2022-11-29 格式:DOCX 页数:22 大小:23.62KB
下载 相关 举报
表单验证验证表单基本验证功能Word文档下载推荐.docx_第1页
第1页 / 共22页
表单验证验证表单基本验证功能Word文档下载推荐.docx_第2页
第2页 / 共22页
表单验证验证表单基本验证功能Word文档下载推荐.docx_第3页
第3页 / 共22页
表单验证验证表单基本验证功能Word文档下载推荐.docx_第4页
第4页 / 共22页
表单验证验证表单基本验证功能Word文档下载推荐.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

表单验证验证表单基本验证功能Word文档下载推荐.docx

《表单验证验证表单基本验证功能Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《表单验证验证表单基本验证功能Word文档下载推荐.docx(22页珍藏版)》请在冰豆网上搜索。

表单验证验证表单基本验证功能Word文档下载推荐.docx

color:

#333333}

input,textarea,select,td{font:

#333333;

border:

1pxsolid#999999;

background:

#ffffff}

table{border-collapse:

collapse;

}

td{padding:

3px}

input{height:

20;

textarea{width:

80%;

height:

50px;

overflow:

auto;

form{display:

inline}

/style>

tablealign="

center"

>

formname="

theForm"

id="

demo"

method="

get"

onSubmit="

returnValidator.Validate(this,2)"

tr>

td>

身份证号:

/td>

inputname="

Card"

dataType="

IdCard"

msg="

身份证号错误"

/tr>

真实姓名:

Name"

Chinese"

真实姓名只允许中文"

ID:

username"

Username"

ID名不符合规定"

英文名:

Nick"

English"

require="

false"

英文名只允许英文字母"

主页:

Homepage"

Url"

非法的Url"

密码:

Password"

SafeString"

密码不符合安全规则"

type="

password"

重复:

Repeat"

to="

两次输入的密码不一致"

信箱:

Email"

信箱格式不正确"

两次输入的信箱不一致"

QQ:

QQ"

QQ号码不存在"

身份证:

身份证号码不正确"

年龄:

Year"

Range"

年龄必须在18~28之间"

min="

18"

max="

28"

年龄1:

Year1"

Compare"

年龄必须在18以上"

operator="

GreaterThanEqual"

电话:

Phone"

电话号码不正确"

手机:

Mobile"

手机号码不正确"

生日:

Birthday"

Date"

format="

ymd"

生日日期不存在"

邮政编码:

Zip"

Custom"

regexp="

^[1-9]\d{5}$"

邮政编码不存在"

Zip1"

操作系统:

selectname="

Operation"

Require"

未选择所用操作系统"

>

optionvalue="

"

选择您所用的操作系统<

/option>

Win98"

Win98<

Win2k"

Win2k<

WinXP"

WinXP<

/select>

所在省份:

广东<

Province"

value="

1"

radio"

陕西<

2"

浙江<

3"

江西<

4"

Group"

必须选定一个省份"

爱好:

运动<

Favorite"

checkbox"

上网<

听音乐<

看书<

必须选择2~3种爱好"

自我介绍:

textareaname="

Description"

Limit"

10"

自我介绍内容必须在10个字之内"

中文是一个字<

/textarea>

自传:

History"

LimitB"

自传内容必须在[3,10]个字节之内"

中文是两个字节t<

相片上传:

up"

Filter"

非法的文件格式"

file"

accept="

jpg,gif,png"

tdcolspan="

Submit"

submit"

确定提交"

inputonClick="

Validator.Validate(document.getElementById('

demo'

))"

检验模式1"

button"

),2)"

检验模式2"

),3)"

检验模式3"

/form>

/table>

script>

/*************************************************

Validatorv1.05

codeby星连建站

wfsr@

*************************************************/

Validator={

Require:

/.+/,

Email:

/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,

Phone:

/^((\(\d{2,3}\))|(\d{3}\-))?

(\(0\d{2,3}\)|0\d{2,3}-)?

[1-9]\d{6,7}(\-\d{1,4})?

$/,

Mobile:

13\d{9}$/,

Url:

/^http:

\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?

%\-&

_~`@[\]\'

:

+!

]*([^<

\"

])*$/,

IdCard:

"

this.IsIdCard(value)"

Currency:

/^\d+(\.\d+)?

Number:

/^\d+$/,

Zip:

/^[1-9]\d{5}$/,

QQ:

/^[1-9]\d{4,8}$/,

Integer:

/^[-\+]?

\d+$/,

Double:

\d+(\.\d+)?

English:

/^[A-Za-z]+$/,

Chinese:

/^[\u0391-\uFFE5]+$/,

Username:

/^[a-z]\w{3,}$/i,

UnSafe:

/^(([A-Z]*|[a-z]*|\d*|[-_\~!

@#\$%\^&

\*\.\(\)\[\]\{\}<

\?

\\\/\'

]*)|.{0,5})$|\s/,

IsSafe:

function(str){return!

this.UnSafe.test(str);

},

SafeString:

this.IsSafe(value)"

Filter:

this.DoFilter(value,getAttribute('

accept'

Limit:

this.limit(value.length,getAttribute('

min'

),getAttribute('

max'

LimitB:

this.limit(this.LenB(value),getAttribute('

Date:

this.IsDate(value,getAttribute('

format'

Repeat:

value==document.getElementsByName(getAttribute('

to'

))[0].value"

Range:

getAttribute('

)<

(value|0)&

&

(value|0)<

getAttribute('

)"

Compare:

pare(value,getAttribute('

operator'

),getAttribute('

Custom:

this.Exec(value,getAttribute('

regexp'

Group:

this.MustChecked(getAttribute('

name'

ErrorItem:

[document.forms[0]],

ErrorMessage:

["

以下原因导致提交失败:

\t\t\t\t"

],

Validate:

function(theForm,mode){

varobj=theForm||event.srcElement;

varcount=obj.elements.length;

this.ErrorMessage.length=1;

this.ErrorItem.length=1;

this.ErrorItem[0]=obj;

for(vari=0;

i<

count;

i++){

with(obj.elements[i]){

var_dataType=getAttribute("

dataType"

);

if(typeof(_dataType)=="

object"

||typeof(this[_dataType])=="

undefined"

)continue;

this.ClearState(obj.elements[i]);

if(getAttribute("

require"

)=="

&

value=="

switch(_dataType){

case"

:

if(!

eval(this[_dataType])){

this.AddError(i,getAttribute("

msg"

));

}

break;

default:

this[_dataType].test(value)){

}

}

}

if(this.ErrorMessage.length>

1){

mode=mode||1;

varerrCount=this.ErrorItem.length;

switch(mode){

case2:

for(vari=1;

errCount;

i++)

this.ErrorItem[i].style.color="

red"

;

case1:

alert(this.ErrorMessage.join("

\n"

this.ErrorItem[1].focus();

break;

case3:

try{

varspan=document.createElement("

SPAN"

span.id="

__ErrorMessagePanel"

span.style.color="

this.ErrorItem[i].parentNode.appendChild(span);

span.innerHTML=this.ErrorMessage[i].replace(/\d+:

/,"

*"

}

catch(e){alert(e.description);

default:

returnfalse;

returntrue;

},

limit:

function(len,min,max){

min=min||0;

max=max||Number.MAX_VALUE;

returnmin<

=len&

len<

=max;

LenB:

function(str){

returnstr.replace(/[^\x00-\xff]/g,"

**"

).length;

ClearState:

function(elem){

with(elem){

if(style.color=="

style.color="

varlastNode=parentNode.childNodes[parentNode.childNodes.length-1];

if(lastNode.id=="

parentNode.removeChild(lastNode);

AddError:

function(index,str){

this.ErrorItem[this.ErrorItem.length]=this.ErrorItem[0].elements[index];

this.ErrorMessage[this.ErrorMessage.length]=this.ErrorMessage.length+"

+str;

Exec:

function(op,reg){

returnnewRegExp(reg,"

g"

).test(op);

compare:

function(op1,operator,op2){

switch(operator){

case"

NotEqual"

return(op1!

=op2);

GreaterThan"

return(op1>

op2);

LessThan"

return(op1<

LessThanEqual"

default:

return(op1==op2);

MustChecked:

function(name,min,max){

vargroups=document.getElementsByName(name);

varhasChecked=0;

min=min||1;

max=max||groups.length;

for(vari=groups.length-1;

i>

=0;

i--)

if(groups[i].checked)hasChecked++;

=hasChecked&

hasChecked<

DoFilter:

function(input,filter){

returnnewRegExp("

^.+\.(?

=EXT)(EXT)$"

.replace(/EXT/g,filter.split(/\s*,\s*/).join("

|"

)),"

gi"

).test(input);

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 经管营销 > 经济市场

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1