Asp学习站欢迎你!

表单(Form)提交检验通用javascript函数

作者:Admin 时间:08-04-21 点击:

本JS程序,可以校验字段是否为空,是否为数字,判断字段长度,检验Email格式,检验是否含有HTML标签等功能
需要的朋友可以把下面的代码COPY后另存为html,HTML文件里详细使用说明。
<html>
<head>
<title>Form提交校验通用javascript函数</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
<style>
body,td,p,input{font-size:14.8px;font-family:"MS Shell Dlg"}
</style>

<script>

var strEmail=/@.+\../
var strHTML=/\<.|\>.$/
function checkBlank(str){
if(!eval(str).value){
return alertMsg(eval(str),"请填写完整信息!")
}
else{
yesok="yes"
}
}

function checkNum(str){
if(yesok=="yes"){
if(!ChkString(eval(str).value)){
return alertMsg(eval(str),"请填写数字")
}
else{
yesok="yes"
}
}
}

function checkMin(str,num){
if(yesok=="yes"){
if(eval(str).value.length<num){
return alertMsg(eval(str),"少了,此栏填写最小长度为"+num)
}
else{
yesok="yes"
}
}
}

function checkMax(str,num){
if(yesok=="yes"){
if(eval(str).value.length>num){
return alertMsg(eval(str),"多了,此栏填写最大长度为"+num)
}
else{
yesok="yes"
}
}
}

function checkMail(str){
if(yesok=="yes"){
if(!strEmail.test(eval(str).value)) {
return alertMsg(eval(str),"请输入正确的邮件地址")
}
else{
yesok="yes"
}
}
}

function checkHTML(str){
if(yesok=="yes"){
if(strHTML.test(eval(str).value)) {
return alertMsg(eval(str),"不能包含HTML字符")
}
else{
yesok="yes"
}
}
}

function splitcheck(str,typename){
checkno=new String(str)
checktype=checkno.split(",")
if(checktype[0]==1){
checkBlank(typename)
}
else{
yesok="yes"
}
if(checktype[1]==1){
checkNum(typename)
}
if(checktype[2]==1){
ch

最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 验证码: 验证码 查看所有评论