很久前写的了..贴来充个数...
JS文件..
/*
* @editor Fatzhan Liang 2008/10/06
* @version 1.0 copyleft
* function: A simple js validator
* but now this codes can only run in the IE5(or higher version),
* compatibility is not considered yet cause lack of knowledge
*/
// public variable
var alltovalidate = new Array();
// initial the form to be validated
function initialForm(formId){
var elements = document.getElementById(formId).elements;
var parent;
var theLabel;
for(var i = 0; i < elements.length; i++){
if (elements[i].patternType == undefined) {
continue;
} else {
alltovalidate.push(elements[i]);
parent = elements[i].parentNode;
theLabel = document.createElement("label");
theLabel.style.visibility = "visible";
theLabel.style.font = "13px Verdana";
parent.appendChild(theLabel);
if (elements[i].type=="checkbox") {
var checkBoxes = document.getElementsByName(elements[i].name);
for (var temp = 0; temp < checkBoxes.length; temp++) {
checkBoxes.item(temp).attachEvent("onfocus", function(){showTip(checkBoxes.item(checkBoxes.length - 1));});
checkBoxes.item(temp).attachEvent("onblur", function(){validateOne(checkBoxes.item(checkBoxes.length - 1));});
}
} else {
elements[i].attachEvent("onfocus", showTip);
elements[i].attachEvent("onblur", validateOne);
}
}
}
}
// show the tip when focus
function showTip(obj){
obj = (obj.name == undefined ? obj.srcElement : obj);
var parent = obj.parentNode;
var theLabel = parent.lastChild;
ValidateRules.chooseTip(obj);
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -40px";
theLabel.innerHTML = "<font color='black'> " + (obj.tip==undefined?ValidateRules.tip:obj.tip) + "</font>";
}
// validate one element
function validateOne(obj){
var isOk = false;
obj = (obj.name == undefined ? obj.srcElement : obj);
var parent = obj.parentNode;
var theLabel = parent.lastChild;
if (obj.value == ""){
if(obj.require == "no"){
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -8px";
theLabel.innerHTML = "<font color='blue'> Empty is OK!</font>";
isOk = true;
} else {
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -104px";
theLabel.innerHTML = "<font color='pink'> " + ValidateRules.warning + "!</font>";
isOk = false;
}
} else if (ValidateRules.doValidate(obj)){
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -8px";
theLabel.innerHTML = "<font color='blue'> OK!</font>";
isOk = true;
} else {
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -72px";
theLabel.innerHTML = "<font color='red'> " + (obj.error==undefined?ValidateRules.error:obj.error) + "!</font>";
isOk = false;
}
return isOk;
}
// validate all elements in the form
function validateForm(formId){
var pass = true;
for(var i = 0; i < alltovalidate.length; i++){
if(!validateOne(alltovalidate[i])) pass = false;
}
if(pass) document.getElementById(formId).submit();
}
// rules and relative functions
ValidateRules = {
tip: "please input",
error: "incorrect format",
warning: "cannot be empty",
require: /.+/,
email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
mobile: /^((\(\d{2,3}\))|(\d{3}\-))?(13|15)\d{9}$/,
phone: /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}\-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
postalcode: /^[1-9]\d{5}$/,
number: /^\d+$/,
integernum: /^[\-\+]?\d+$/,
doublenum: /^[\-\+]?[\d]+(\.[\d]+)?$/,
name: /^[\w\u4e00-\u9fa5\-]{1,20}$/,
username: /^\w{5,20}$/,
english: /^[A-Za-z]+$/,
chinese: /^[\u0391-\uFFE5]+$/,
varchar: /^[\w\W]{0,255}$/,
qq: /^[1-9]\d{4,9}$/,
url: /^(http:\/\/)?[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
unsafe: /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
safestring: "this.isSafe(value)",
date: "this.isDate(value, getAttribute('format'))",
idcard: "this.isIdCard(value)",
filter: "this.doFilter(value, getAttribute('accept'))",
limit: "this.doLimit(value.length,getAttribute('min'), getAttribute('max'))",
limitbyte: "this.doLimit(this.doLimitByte(value), getAttribute('min'), getAttribute('max'))",
repeat: "value == document.getElementById(getAttribute('match')).value",
range: "getAttribute('min') < (value|0) && (value|0) < getAttribute('max')",
compare: "this.doCompare(value,getAttribute('var'),getAttribute('type'))",
group: "this.doChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
select: "value != -1",
//selectMuti: "",
custom: "this.verifyCustom(getAttribute('pattern'), value)",
isSafe: function(input){
return !this.unsafe.test(input);
},
isDate: function(input, format){
switch(format){
case "ymd":
return /^(18|19|20|21)\d{2}-(0?\d|1[012])-(0?\d|[12]\d|3[01])$/.test(input);
break;
case "dmy":
return /^(0?\d|[12]\d|3[01]),(0?\d|1[012]),(18|19|20|21)\d{2}$/.test(input);
break;
default:
break;
}
},
isIdCard: function(input){
return true;
},
doFilter: function(input, acceptIn){
return new RegExp("^.+\.(?=INS)(INS)$".replace(/INS/g, acceptIn.split(/\s*,\s*/).join("|")), "gi").test(input);
},
doLimit: function(size, min, max){
min = min || 0;
max = max || Number.MAX_VALUE;
return min <= size && size <= max;
},
doLimitByte: function(input){
return input.replace(/[^\x00-\xff]/g,"**").length;
},
doCompare: function(input, cmp, type){
switch(type){
case "lt": return (input < cmp);
case "le": return (input <= cmp);
case "eq": return (input == cmp);
case "gt": return (input > cmp);
case "ge": return (input >= cmp);
case "ne": return (input != cmp);
default: return true;
}
},
doChecked: function(name, min, max){
var checkBoxes = document.getElementsByName(name);
var isChecked = 0;
min = min || 1;
max = max || checkBoxes.length;
for(var i = 0; i < checkBoxes.length; i++) {
if(checkBoxes[i].checked)
isChecked++;
}
return isChecked >= min && isChecked <= max;
},
verifyCustom: function(input, pattern){
return new RegExp(pattern,"gi").test(input);
},
chooseTip: function(obj){
with(obj){
var patternType = getAttribute("patternType");
if(typeof(patternType) == "object" || typeof(this[patternType]) == "undefined") {
return;
}
switch(patternType){
case "email": this.tip = "email format like fat@hotmail.com"; break;
case "mobile": this.tip = "mobile like (xx-)xxxxxxxxxxx"; break;
case "phone": this.tip = "separate the tele area num by '-'"; break;
case "postalcode": this.tip ="input a postalcode"; break;
case "number": this.tip = "input a correct number"; break;
case "integernum": this.tip = "input a integer"; break;
case "doublenum": this.tip = "input a double"; break;
case "name": this.tip = "chinese,english,'-'or'_' less than 20"; break;
case "username": this.tip = "english or number between 5 and 20"; break;
case "chinese": this.tip = "input chinese"; break;
case "varchar": this.tip = "less than 255 words"; break;
case "qq": this.tip = "input a correct qq"; break;
case "url": this.tip = "input a correct url"; break;
case "date": getAttribute("format") == "ymd" ? this.tip = "date format 2000-01-01" : this.tip = "date format 01,01,2000"; break;
case "safestring": this.tip = "larger than 5 words, do not use letter or number only"; break;
case "idcard": this.tip = "input a correct idcard"; break;
case "filter": this.tip = "only accept " + getAttribute("accept") + " format"; break;
case "limit": this.tip = "lenght between " + getAttribute("min") + " and " + getAttribute("max"); break;
case "limitbyte": this.tip = "only accept " + getAttribute("min") + " and " + getAttribute("max") + "bytes"; break;
case "repeat": this.tip = "repeat the last input"; break;
case "range": this.tip = "less than " + getAttribute("max") + " and greater than " + getAttribute("min"); break;
case "compare": this.tip = getAttribute("type") + " value " + getAttribute("var"); break;
case "group": this.tip = "must check " + getAttribute("min") + " to " + getAttribute("max"); break;
case "select": this.tip = "must select a value"; break;
default : break;
}
}
},
doValidate: function(obj){
var success = false;
with(obj){
var patternType = getAttribute("patternType");
if(typeof(patternType) == "object" || typeof(this[patternType]) == "undefined") {
success = false;
}
switch(patternType){
case "safestring":
case "repeat":
case "date":
case "idcard":
case "filter":
case "limit":
case "limitbyte":
case "range":
case "compare":
case "group":
case "select":
case "custom":
if(eval(this[patternType])) {
success = true;
}
break;
default:
if(this[patternType].test(value)){
success = true;
}
break;
}
}
return success;
}
}
function addEvent(node, evType, fn) {
if(node.addEventListener){
node.addEventListener(evType, fn, false);
return true;
} else if (node.attachEvent) {
alert("node.attachevent");
var r = node.attachEvent("on" + evType, fn);
return r;
} else {
alert(node["on" + evType]);
node["on" + evType] = fn;
}
}
=====================================
Html文件测试:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled1</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="MyValidator.js"></script>
</head>
<body onload="initialForm('testform');">
This is my HTML page. <br>
<form id="testform" action="comeon.html">
<table style="font: 14px Verdana">
<tr>
<th>username:</th>
<td><input name="input1" type="text" patternType="username"></td>
</tr>
<tr>
<th>password:</th>
<td><input id="password" name="input1" type="password" patternType="safestring"></td>
</tr>
<tr>
<th>repeat psw:</th>
<td><input name="input1" type="password" patternType="repeat" match="password"></td>
</tr>
<tr>
<th>your name:</th>
<td><input name="input1" type="text" patternType="name"></td>
</tr>
<tr>
<th>sex:</th>
<td><select name="select" patternType="select">
<option value="-1">your sex:</option>
<option value="0">GG</option>
<option value="1">MM</option>
<option value="1">MG</option>
</select></td>
</tr>
<tr>
<th>age:</th>
<td><input type="text" patternType="range" min="18" max="100" tip="age should between 18 and 100" error="you are too old or too young"/></td>
</tr>
<tr>
<th>birthday:</th>
<td><input name="input1" type="text" patternType="date" format="ymd" error="custom error1"/></td>
</tr>
<tr>
<th>idcard:</th>
<td><input name="input1" type="text" patternType="idcard"/>(未实现)</td>
</tr>
<tr>
<th>qq:</th>
<td><input name="input1" type="text" patternType="qq"/></td>
</tr>
<tr>
<th>email:</th>
<td><input name="input2" type="text" patternType="email"></td>
</tr>
<tr>
<th>favorite:</th>
<td><input type="checkbox" name="shit"/>jump <input type="checkbox" name="shit"/>fly <input type="checkbox" name="shit" validate="true" patternType="group" min="0" max="2"/>sleep</td>
</tr>
<tr>
<th>your head:</th>
<td><input name="input5" type="file" patternType="filter" accept="jpg,jpeg,png,gif"/></td>
</tr>
<tr>
<th>telephone:</th>
<td><input name="input3" patternType="phone" require="no"></td>
</tr>
<tr>
<th>moblie:</th>
<td><input name="input3" patternType="mobile"></td>
</tr>
<tr>
<th>postalcode:</th>
<td><input patternType="postalcode"/></td>
</tr>
<tr>
<th>your website:</th>
<td><input name="input3" patternType="url"></td>
</tr>
<tr>
<th>self intro:</th>
<td><textarea name="input4" cols="30" rows="5" patternType="limit" min="20" max="255"></textarea></td>
</tr>
<tr>
<th>test userdefined:</th>
<td><input name="input3" patternType="custom" pattern="I am a pig" tip="please input 'I am a pig'" error="you're not a pig"></td>
</tr>
<tr>
<td colspan="2" align="left"><input type="button" value="submit" onclick="validateForm('testform')"/>
<input type="reset" value="reset"/></td>
</tr>
</table>
</form>
</body>
</html>
JS文件..
/*
* @editor Fatzhan Liang 2008/10/06
* @version 1.0 copyleft
* function: A simple js validator
* but now this codes can only run in the IE5(or higher version),
* compatibility is not considered yet cause lack of knowledge
*/
// public variable
var alltovalidate = new Array();
// initial the form to be validated
function initialForm(formId){
var elements = document.getElementById(formId).elements;
var parent;
var theLabel;
for(var i = 0; i < elements.length; i++){
if (elements[i].patternType == undefined) {
continue;
} else {
alltovalidate.push(elements[i]);
parent = elements[i].parentNode;
theLabel = document.createElement("label");
theLabel.style.visibility = "visible";
theLabel.style.font = "13px Verdana";
parent.appendChild(theLabel);
if (elements[i].type=="checkbox") {
var checkBoxes = document.getElementsByName(elements[i].name);
for (var temp = 0; temp < checkBoxes.length; temp++) {
checkBoxes.item(temp).attachEvent("onfocus", function(){showTip(checkBoxes.item(checkBoxes.length - 1));});
checkBoxes.item(temp).attachEvent("onblur", function(){validateOne(checkBoxes.item(checkBoxes.length - 1));});
}
} else {
elements[i].attachEvent("onfocus", showTip);
elements[i].attachEvent("onblur", validateOne);
}
}
}
}
// show the tip when focus
function showTip(obj){
obj = (obj.name == undefined ? obj.srcElement : obj);
var parent = obj.parentNode;
var theLabel = parent.lastChild;
ValidateRules.chooseTip(obj);
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -40px";
theLabel.innerHTML = "<font color='black'> " + (obj.tip==undefined?ValidateRules.tip:obj.tip) + "</font>";
}
// validate one element
function validateOne(obj){
var isOk = false;
obj = (obj.name == undefined ? obj.srcElement : obj);
var parent = obj.parentNode;
var theLabel = parent.lastChild;
if (obj.value == ""){
if(obj.require == "no"){
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -8px";
theLabel.innerHTML = "<font color='blue'> Empty is OK!</font>";
isOk = true;
} else {
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -104px";
theLabel.innerHTML = "<font color='pink'> " + ValidateRules.warning + "!</font>";
isOk = false;
}
} else if (ValidateRules.doValidate(obj)){
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -8px";
theLabel.innerHTML = "<font color='blue'> OK!</font>";
isOk = true;
} else {
theLabel.style.background = "url(validator_image.gif) no-repeat 1px -72px";
theLabel.innerHTML = "<font color='red'> " + (obj.error==undefined?ValidateRules.error:obj.error) + "!</font>";
isOk = false;
}
return isOk;
}
// validate all elements in the form
function validateForm(formId){
var pass = true;
for(var i = 0; i < alltovalidate.length; i++){
if(!validateOne(alltovalidate[i])) pass = false;
}
if(pass) document.getElementById(formId).submit();
}
// rules and relative functions
ValidateRules = {
tip: "please input",
error: "incorrect format",
warning: "cannot be empty",
require: /.+/,
email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
mobile: /^((\(\d{2,3}\))|(\d{3}\-))?(13|15)\d{9}$/,
phone: /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}\-)?[1-9]\d{6,7}(\-\d{1,4})?$/,
postalcode: /^[1-9]\d{5}$/,
number: /^\d+$/,
integernum: /^[\-\+]?\d+$/,
doublenum: /^[\-\+]?[\d]+(\.[\d]+)?$/,
name: /^[\w\u4e00-\u9fa5\-]{1,20}$/,
username: /^\w{5,20}$/,
english: /^[A-Za-z]+$/,
chinese: /^[\u0391-\uFFE5]+$/,
varchar: /^[\w\W]{0,255}$/,
qq: /^[1-9]\d{4,9}$/,
url: /^(http:\/\/)?[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,
unsafe: /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,
safestring: "this.isSafe(value)",
date: "this.isDate(value, getAttribute('format'))",
idcard: "this.isIdCard(value)",
filter: "this.doFilter(value, getAttribute('accept'))",
limit: "this.doLimit(value.length,getAttribute('min'), getAttribute('max'))",
limitbyte: "this.doLimit(this.doLimitByte(value), getAttribute('min'), getAttribute('max'))",
repeat: "value == document.getElementById(getAttribute('match')).value",
range: "getAttribute('min') < (value|0) && (value|0) < getAttribute('max')",
compare: "this.doCompare(value,getAttribute('var'),getAttribute('type'))",
group: "this.doChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",
select: "value != -1",
//selectMuti: "",
custom: "this.verifyCustom(getAttribute('pattern'), value)",
isSafe: function(input){
return !this.unsafe.test(input);
},
isDate: function(input, format){
switch(format){
case "ymd":
return /^(18|19|20|21)\d{2}-(0?\d|1[012])-(0?\d|[12]\d|3[01])$/.test(input);
break;
case "dmy":
return /^(0?\d|[12]\d|3[01]),(0?\d|1[012]),(18|19|20|21)\d{2}$/.test(input);
break;
default:
break;
}
},
isIdCard: function(input){
return true;
},
doFilter: function(input, acceptIn){
return new RegExp("^.+\.(?=INS)(INS)$".replace(/INS/g, acceptIn.split(/\s*,\s*/).join("|")), "gi").test(input);
},
doLimit: function(size, min, max){
min = min || 0;
max = max || Number.MAX_VALUE;
return min <= size && size <= max;
},
doLimitByte: function(input){
return input.replace(/[^\x00-\xff]/g,"**").length;
},
doCompare: function(input, cmp, type){
switch(type){
case "lt": return (input < cmp);
case "le": return (input <= cmp);
case "eq": return (input == cmp);
case "gt": return (input > cmp);
case "ge": return (input >= cmp);
case "ne": return (input != cmp);
default: return true;
}
},
doChecked: function(name, min, max){
var checkBoxes = document.getElementsByName(name);
var isChecked = 0;
min = min || 1;
max = max || checkBoxes.length;
for(var i = 0; i < checkBoxes.length; i++) {
if(checkBoxes[i].checked)
isChecked++;
}
return isChecked >= min && isChecked <= max;
},
verifyCustom: function(input, pattern){
return new RegExp(pattern,"gi").test(input);
},
chooseTip: function(obj){
with(obj){
var patternType = getAttribute("patternType");
if(typeof(patternType) == "object" || typeof(this[patternType]) == "undefined") {
return;
}
switch(patternType){
case "email": this.tip = "email format like fat@hotmail.com"; break;
case "mobile": this.tip = "mobile like (xx-)xxxxxxxxxxx"; break;
case "phone": this.tip = "separate the tele area num by '-'"; break;
case "postalcode": this.tip ="input a postalcode"; break;
case "number": this.tip = "input a correct number"; break;
case "integernum": this.tip = "input a integer"; break;
case "doublenum": this.tip = "input a double"; break;
case "name": this.tip = "chinese,english,'-'or'_' less than 20"; break;
case "username": this.tip = "english or number between 5 and 20"; break;
case "chinese": this.tip = "input chinese"; break;
case "varchar": this.tip = "less than 255 words"; break;
case "qq": this.tip = "input a correct qq"; break;
case "url": this.tip = "input a correct url"; break;
case "date": getAttribute("format") == "ymd" ? this.tip = "date format 2000-01-01" : this.tip = "date format 01,01,2000"; break;
case "safestring": this.tip = "larger than 5 words, do not use letter or number only"; break;
case "idcard": this.tip = "input a correct idcard"; break;
case "filter": this.tip = "only accept " + getAttribute("accept") + " format"; break;
case "limit": this.tip = "lenght between " + getAttribute("min") + " and " + getAttribute("max"); break;
case "limitbyte": this.tip = "only accept " + getAttribute("min") + " and " + getAttribute("max") + "bytes"; break;
case "repeat": this.tip = "repeat the last input"; break;
case "range": this.tip = "less than " + getAttribute("max") + " and greater than " + getAttribute("min"); break;
case "compare": this.tip = getAttribute("type") + " value " + getAttribute("var"); break;
case "group": this.tip = "must check " + getAttribute("min") + " to " + getAttribute("max"); break;
case "select": this.tip = "must select a value"; break;
default : break;
}
}
},
doValidate: function(obj){
var success = false;
with(obj){
var patternType = getAttribute("patternType");
if(typeof(patternType) == "object" || typeof(this[patternType]) == "undefined") {
success = false;
}
switch(patternType){
case "safestring":
case "repeat":
case "date":
case "idcard":
case "filter":
case "limit":
case "limitbyte":
case "range":
case "compare":
case "group":
case "select":
case "custom":
if(eval(this[patternType])) {
success = true;
}
break;
default:
if(this[patternType].test(value)){
success = true;
}
break;
}
}
return success;
}
}
function addEvent(node, evType, fn) {
if(node.addEventListener){
node.addEventListener(evType, fn, false);
return true;
} else if (node.attachEvent) {
alert("node.attachevent");
var r = node.attachEvent("on" + evType, fn);
return r;
} else {
alert(node["on" + evType]);
node["on" + evType] = fn;
}
}
=====================================
Html文件测试:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled1</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="MyValidator.js"></script>
</head>
<body onload="initialForm('testform');">
This is my HTML page. <br>
<form id="testform" action="comeon.html">
<table style="font: 14px Verdana">
<tr>
<th>username:</th>
<td><input name="input1" type="text" patternType="username"></td>
</tr>
<tr>
<th>password:</th>
<td><input id="password" name="input1" type="password" patternType="safestring"></td>
</tr>
<tr>
<th>repeat psw:</th>
<td><input name="input1" type="password" patternType="repeat" match="password"></td>
</tr>
<tr>
<th>your name:</th>
<td><input name="input1" type="text" patternType="name"></td>
</tr>
<tr>
<th>sex:</th>
<td><select name="select" patternType="select">
<option value="-1">your sex:</option>
<option value="0">GG</option>
<option value="1">MM</option>
<option value="1">MG</option>
</select></td>
</tr>
<tr>
<th>age:</th>
<td><input type="text" patternType="range" min="18" max="100" tip="age should between 18 and 100" error="you are too old or too young"/></td>
</tr>
<tr>
<th>birthday:</th>
<td><input name="input1" type="text" patternType="date" format="ymd" error="custom error1"/></td>
</tr>
<tr>
<th>idcard:</th>
<td><input name="input1" type="text" patternType="idcard"/>(未实现)</td>
</tr>
<tr>
<th>qq:</th>
<td><input name="input1" type="text" patternType="qq"/></td>
</tr>
<tr>
<th>email:</th>
<td><input name="input2" type="text" patternType="email"></td>
</tr>
<tr>
<th>favorite:</th>
<td><input type="checkbox" name="shit"/>jump <input type="checkbox" name="shit"/>fly <input type="checkbox" name="shit" validate="true" patternType="group" min="0" max="2"/>sleep</td>
</tr>
<tr>
<th>your head:</th>
<td><input name="input5" type="file" patternType="filter" accept="jpg,jpeg,png,gif"/></td>
</tr>
<tr>
<th>telephone:</th>
<td><input name="input3" patternType="phone" require="no"></td>
</tr>
<tr>
<th>moblie:</th>
<td><input name="input3" patternType="mobile"></td>
</tr>
<tr>
<th>postalcode:</th>
<td><input patternType="postalcode"/></td>
</tr>
<tr>
<th>your website:</th>
<td><input name="input3" patternType="url"></td>
</tr>
<tr>
<th>self intro:</th>
<td><textarea name="input4" cols="30" rows="5" patternType="limit" min="20" max="255"></textarea></td>
</tr>
<tr>
<th>test userdefined:</th>
<td><input name="input3" patternType="custom" pattern="I am a pig" tip="please input 'I am a pig'" error="you're not a pig"></td>
</tr>
<tr>
<td colspan="2" align="left"><input type="button" value="submit" onclick="validateForm('testform')"/>
<input type="reset" value="reset"/></td>
</tr>
</table>
</form>
</body>
</html>
相关推荐
JS验证代码大全是汇集了多种JavaScript验证技术的资源集合,可以帮助开发者在创建网页表单、验证用户输入等方面提供有效的解决方案。 一、表单验证基础 在网页开发中,表单验证是非常重要的一环,它能够确保用户...
本文将详细介绍一种JavaScript验证数字的方法,并通过具体的代码示例来解释其实现原理。 #### 二、需求分析 根据题目提供的信息,我们需要实现一个功能:验证用户输入的文本框中的值是否为长度为6位的纯数字。具体...
JavaScript(简称JS)是一种轻量级的编程语言,主要用于网页和网络应用的开发。它能够直接在客户端运行,无需...通过深入研究`pubcheck.js`的源代码,我们可以学习到更多关于JavaScript验证策略和实现方式的知识。
"js验证大全"是一个集合了多种JavaScript验证技术和特效的资源包,对于程序员来说,它是一个非常宝贵的参考资料。 首先,我们来看一下这个压缩包中包含的文件: 1. **Default.aspx**:这是一个ASP.NET网页文件,...
JavaScript,简称JS,是网页开发中不可或缺的一部分,主要用于实现客户端的交互逻辑和增强用户体验。本篇文章将深入探讨三个关键知识点:JS表单验证、JS导出Excel以及JS验证。 一、JS表单验证 在Web应用程序中,...
JavaScript验证框架是Web开发中常用的一种工具,它用于在客户端对用户输入的数据进行实时检查,以确保数据的有效性和合规性,从而减少服务器端的压力并提供更好的用户体验。本项目提供的"js验证框架"是一个轻量级的...
总结,这个"js 验证 自定义 类"框架旨在提供一种高效、灵活和可扩展的JavaScript验证解决方案。通过其内置的基本验证功能和自定义规则的能力,开发者可以轻松应对各种数据验证需求,同时保持良好的用户体验。结合...
### JS验证方法大全 在Web开发中,JavaScript(简称JS)是一种非常重要的客户端脚本语言,广泛用于网页交互效果的实现。其中,数据验证是非常关键的一环,它可以帮助开发者确保用户输入的数据符合预期的格式或者...
在JavaScript(JS)中,验证错误信息是网页前端开发中不可或缺的部分。这通常涉及到用户输入数据的检查,确保数据的有效性和安全性。"js验证错误信息.rar" 包含的资源显然是一个封装了验证功能的JS类,适用于文本框...
根据给定文件的信息,本文将详细介绍如何使用JavaScript(简称JS)进行输入验证,具体包括三种情况:一是确保用户只能输入数字;二是确保用户输入的是字母、数字或下划线;三是验证固定电话号码的格式是否正确。这三...
在Web开发中,JavaScript验证扮演着至关重要的角色,它能够提高用户体验,减少服务器负担,防止无效或错误的数据提交。本文将深入探讨JavaScript验证的各种方法和应用场景。 1. **基础验证** - **非空验证**:检查...
总之,JavaScript验证在密码修改过程中扮演着至关重要的角色,它可以确保用户输入的数据满足特定的安全标准,从而提高整个系统的安全性。正确实现和使用这些验证技术,对于创建一个用户友好且安全的Web应用至关重要...
在网页开发中,JavaScript(简称JS)是一种必不可少的前端编程语言,它被广泛用于处理用户交互,其中之一就是验证用户在表单中输入的数据格式。表单验证能够确保用户提交的信息符合预设的标准,例如正确的电话号码、...
js验证居民身份证,就这么简单,你懂得~
3. ComboBoxCheckTree.js:这是主要的JavaScript文件,很可能包含了ComboBoxCheckTree组件的逻辑代码,包括数据加载、用户交互处理、验证功能等。 4. treedata.js:这是一个可能存储树形数据的文件,数据可能以JSON...
总结来说,本文所列出的JavaScript验证和函数汇总,对于前端开发人员在处理数值和验证输入时提供了有价值的工具,不仅减少了重复编写验证代码的工作量,还确保了数据处理的准确性,提高开发效率和代码质量。...
**JavaScript验证**在Web开发中扮演着重要角色,主要用于确保用户在表单中输入的数据符合特定格式或规则,例如检查邮箱格式、手机号码合法性、密码强度等。在没有服务器端验证的情况下,JavaScript验证能提供即时...
JavaScript验证主要分为客户端验证和服务器端验证。客户端验证通常通过JavaScript在用户提交表单前进行,可以实时反馈错误信息,减少不必要的服务器请求,提高响应速度。而服务器端验证则是为了防止恶意用户绕过...