Javascript实现的自动验证函数
作者:互联网
2009-06-09
test.htm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
33
34
35
validate.js
1function validate(){
2
3 //var objs = document.all;
4 //var Elements = document.getElementsByTagName("*");
5 var Elements;
6 var ctlArray;
7 var ctlArrayName;
8 var i, j;
9 var elLen, arrLen;
10 var msgs;
11
12 Elements = document.getElementsByTagName("input");
13 arrName ="";
14
15 for ( i in Elements ) {
16 elLen = Elements[i].length;
17
18 if (elLen > 1) {
19 ctlArray = Elements[i];
20 arrLen = ctlArray.length;
21
22 if (arrName != ctlArray[0].name) {
23 arrName = ctlArray[0].name;
24
25 for (j=0; j < arrLen; j++) {
26 if (checkValue(ctlArray[j]) == false) {
27 return false;
28 }
29 }
30
31 }
32
33 }else{
34
35 if (checkValue(Elements[i]) == false) {
36 return false;
37 }
38 }
39 }
40
41 return true;
42}
43
44function checkValue (obj){
45
46 var len;
47 len = obj.maxLength;
48
49 if ( obj.type == "text" ) {
50
51 //if (obj.msg != undefined ) {
52 if ( obj.msg ) {
53 msgs = obj.msg.split(",");
54 } else {
55 return true;
56 }
57
58 if ( trim(obj.value) == "" && obj.mustitem && obj.mustitem == "true") {
59 alert(msgs[0]);
60 getFocusSelect(obj);
61 return false;
62 }else {
63
64 if ( trim(obj.value) != ""&& obj.feildtype && obj.feildtype == "integer" ) {
65
66 if ( checkNumLen(obj.value, len) == false ) {
67 alert(msgs[1]);
68 getFocusSelect(obj);
69 return false;
70 }
71
72 } else if ( trim(obj.value) != "" && obj.feildtype && obj.feildtype == "string" ) {
73
74 if ( getLenthByByte(trim(obj.value)) > len){
75 alert(msgs[1]);
76 getFocusSelect(obj);
77 return false;
78 }
79 }
80 }
81 }
82
83}
message.inc 1<%
2Const IMSG0001 = "ID必须输入!"
3Const IMSG0002 = "ID输入格式错误!"
4Const IMSG0003 = "名称必须输入!"
5Const IMSG0004 = "名称输入格式错误!"
6%>
相关标签:
相关推荐
专题
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
+ 收藏
最新数据
相关文章
「性能优化」虚拟列表极致优化实战:从原理到源码,打造丝滑滚动体验
你的 Vue 3 生命周期,VuReact 会编译成什么样的 React?
你的 Vue 3 defineProps(),VuReact 会编译成什么样的 React?
Vue条件渲染详解:v-if、v-show用法与实战指南
前端性能内卷终点?Signals 正在重塑我们的开发习惯
使用 IntersectionObserver + 哨兵元素实现长列表懒加载
大屏卡成 PPT?这 3 个性能优化招数亲测有效
别再用 JSON.parse 深拷贝了,聊聊 StructuredClone
当 Vue 3 遇上桥接模式:手把手教你优雅剥离虚拟滚动的业务大泥球
VueUse 全面指南|Vue3组合式工具集实战
AI精选
Billie Eilish 卡通版 3D 渲染提示词
从程序员到AI工程师:距离有多远?附全套学习路线图
ArkClaw 养虾省钱攻略,这 10% 的返利你还不知道?
大模型就是你雇的员工:从职场管理学看 AI 协作范式的三次进化
MinerU JS/TS SDK 深度指南:JavaScript/TypeScript 开发者的 PDF/文档解析利器
AI 自动值夜班时代来了!Claude Code 刚刚推出 Routines
一天一个开源项目(第74篇):OpenCLI - 把任意网站变成零成本 CLI 工具的 AI Agent 基础设施
就在刚刚,腾讯版 Hermes Agent 来了!快速部署,安装即用!
