PageRenderTime 26ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/ruhlamat_website/Inc/jsvalidator/js/JSValidator_v1.0.js

http://demoasp.googlecode.com/
JavaScript | 783 lines | 665 code | 40 blank | 78 comment | 69 complexity | 5892cbe814b76888311608fc0076d8fb MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <!--
  2. var JSValidator={
  3. /***?????????????????????**/
  4. setup:function(formid){
  5. var targetForm=JSValidator.Tools.$(formid); //????????
  6. var tagArr = targetForm.getElementsByTagName("my:tag"); //?????????
  7. //alert("??????:"+tagArr.length);
  8. //??????? ????
  9. for(var i=0;i<tagArr.length;i++){
  10. ValidateFactory.GetValidateField(tagArr[i],i);
  11. }
  12. /**????? onsubmit?? ??*/
  13. JSValidator.Tools.AddEventFunc(targetForm,"onsubmit",JSValidator.validateBeforeSub,tagArr);
  14. },
  15. /**??????????**/
  16. tipuser:function(formElement){
  17. //?? ???????
  18. var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
  19. // ???tag?? ??? Bean
  20. var Bean = new JSValidator.validateBean();
  21. Bean.initTag(tag);
  22. JSValidator.Message.Show(Bean,"tips");
  23. },
  24. /**????????????**/
  25. validateForm:{
  26. submit:true //???????
  27. },
  28. /**? ?????? ??**/
  29. validateBeforeSub:function(targetForm,tags){
  30. //??? ???????
  31. JSValidator.validateForm.submit = true;
  32. for(var i=0;i<tags.length;i++){
  33. var Bean = new JSValidator.validateBean();
  34. Bean.initTag(tags[i]);
  35. var s1 = Bean.getRule().indexOf("||");
  36. var s2 = Bean.getRule().indexOf("&&");
  37. var operate="";
  38. /**???? ?????? ? ????? ????**/
  39. if((s1!=-1)||(s2!=-1)){ //???????????
  40. if(Bean.getRule().indexOf("compare")!=-1){
  41. throw new Error("rule??????????'copare'????????????rule????");
  42. return false;
  43. }else if(Bean.getRule().indexOf("custom")!=-1){
  44. throw new Error("rule??????????'custom'????????????rule????");
  45. return false;
  46. }else if(s1!=-1&&s2!=-1){
  47. throw new Error("rule???????????????? ????????rule????");
  48. return false;
  49. }else{
  50. operate = s1!=-1?"||":"&&"; //?????
  51. }
  52. }
  53. switch(Bean.getRule()){
  54. case "limit":
  55. JSValidator.Core.valForLimit(JSValidator.Tools.$(Bean.getFor()));
  56. break;
  57. case "compare":
  58. JSValidator.Core.valForCompare(JSValidator.Tools.$(Bean.getFor()));
  59. break;
  60. case "custom":
  61. JSValidator.Core.valForCustom(JSValidator.Tools.$(Bean.getFor()));
  62. break;
  63. default :
  64. /***????????? ?????? onblur??****/
  65. JSValidator.Core.validate(JSValidator.Tools.$(Bean.getFor()),operate);
  66. break;
  67. }
  68. }
  69. },
  70. /**?????????***/
  71. regulation:{
  72. /**???????**/
  73. simple:{
  74. notempty : /.+/,//???
  75. email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,//email??
  76. phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,//?????????????
  77. mobile : /^((\(\d{2,3}\))|(\d{3}\-))?((13\d{9})|(15[389]\d{8}))$/,//????
  78. url : /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"])*$/,//url??
  79. ip : /^(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5]).(0|[1-9]\d?|[0-1]\d{2}|2[0-4]\d|25[0-5])$/,//ip????
  80. currency : /^\d+(\.\d+)?$/,//????
  81. number : /^\d+$/,//????
  82. zip : /^[1-9]\d{5}$/,//??????
  83. qq : /^[1-9]\d{4,8}$/,//??QQ???5~9?
  84. english : /^[A-Za-z]+$/,//????
  85. chinese : /^[\u0391-\uFFE5]+$/,//??
  86. username : /^[a-z]\w{3,19}$/i,//???????????3~19???
  87. password : /^\w{8,19}$/i,
  88. integer : /^[-\+]?(?:\d|[1-9]\d+)$/,//????
  89. double : /^[-\+]?(?:\d|[1-9]\d+)(\.\d+)?$/,//??????????????
  90. date:/^(19\d{2}|2\d{3})-(0?[1-9]|1[0-2])-((0?[1-9])|((1|2)[0-9])|30|31)$/, //????
  91. datetime:/^(19\d{2}|2\d{3})-(0?[1-9]|1[0-2])-((0?[1-9])|((1|2)[0-9])|30|31) ((0?\d)|(1\d|2[0-3]))(:(0?\d|[1-5]\d)){2}$/ //??????
  92. },
  93. /**???????*/
  94. complex:{
  95. compare:function(source,target,type,mode){//target???source?? ,type:???? mode?????
  96. var reg = null;
  97. var result = false;
  98. // ???
  99. if(type=="string"){
  100. switch(mode){
  101. case "equal":
  102. reg = new RegExp("^"+source+"$","i");
  103. break;
  104. case "notequal":
  105. reg = new RegExp("^"+source+"$","i");
  106. result = !reg.test(target);
  107. reg = null;
  108. break;
  109. case "greaterthan":
  110. result = source>target;
  111. break;
  112. case "greaterthanequal":
  113. result = source>=target;
  114. break;
  115. case "lessthan":
  116. result = source<target;
  117. break;
  118. case "lessthanequal":
  119. result = source<=target;
  120. break;
  121. }
  122. }
  123. // ??
  124. else if(type=="number"){
  125. if(isNaN(source)){return false;}
  126. var sr = parseFloat(source);
  127. var tg = parseFloat(target);
  128. switch(mode){
  129. case "equal":
  130. result = sr==tg;
  131. break;
  132. case "notequal":
  133. result = sr!=tg;
  134. break;
  135. case "greaterthan":
  136. result = sr>tg;
  137. break;
  138. case "greaterthanequal":
  139. result = sr>=tg;
  140. break;
  141. case "lessthan":
  142. result = sr<tg;
  143. break;
  144. case "lessthanequal":
  145. result = sr<=tg;
  146. break;
  147. }
  148. }
  149. //??
  150. else{
  151. var sr = JSValidator.Tools.GetDateFromStr(source);
  152. var tg = JSValidator.Tools.GetDateFromStr(target);
  153. var b = (!(sr>tg))&&(!(sr<tg));
  154. switch(mode){
  155. case "equal":
  156. result = b;
  157. break;
  158. case "notequal":
  159. result = !b;
  160. break;
  161. case "greaterthan":
  162. result = (sr>tg&&b==false);
  163. break;
  164. case "greaterthanequal":
  165. result = (sr>tg||b==true);
  166. break;
  167. case "lessthan":
  168. result = (sr<tg&&b==false);
  169. break;
  170. case "lessthanequal":
  171. result = (sr<tg||b==true);
  172. break;
  173. }
  174. }
  175. result = reg?reg.test(target):result;
  176. reg=null;
  177. return result;
  178. },
  179. limit:function(source,Bean){
  180. var res = true;
  181. for(var v in Bean["limits"]){
  182. if(Bean["limits"][v]!=null){
  183. b = this.testLimit(source,Bean.getAs(),Bean["limits"],v);
  184. if(b==false){
  185. res = false;
  186. break;
  187. }
  188. }
  189. }
  190. return res;
  191. },
  192. custom:function(source,expression){
  193. var reg = new RegExp(expression);
  194. return reg.test(source);
  195. },
  196. // ?? ???? ???????
  197. testLimit:function(value,type,option,limits){
  198. var reg = null;
  199. var result = false;
  200. var str ="";
  201. if(type=="string"){ //??
  202. switch(limits){
  203. case "min":
  204. reg = new RegExp("^.{"+option["min"]+",}$"); //??? ????
  205. break;
  206. case "max":
  207. reg = new RegExp("^.{0,"+option["max"]+"}$"); //??? ????
  208. break;
  209. case "enum": //??? ?,??
  210. str="";
  211. var enums = option["enum"].split(",");
  212. for(var v in enums){
  213. str+=enums[v]+"|";
  214. }
  215. str = str.substring(0,str.length-1);
  216. reg = new RegExp("^(?:"+str+")$");
  217. break;
  218. case "except": //??? ?,??
  219. str="";
  220. var excepts = option["except"].split(",");
  221. for(var v in excepts){
  222. str+=excepts[v]+"|";
  223. }
  224. str = str.substring(0,str.length-1);
  225. reg = new RegExp("^(?:"+str+")$");
  226. result = reg.test(value)?false:true;
  227. reg = null;
  228. break;
  229. case "beginwith": //????,??
  230. str="";
  231. var begins = option["beginwith"].split(",");
  232. for(var v in begins){
  233. str+=begins[v]+"|";
  234. }
  235. str = str.substring(0,str.length-1);
  236. reg = new RegExp("^(?:"+str+").*$","i");
  237. break;
  238. case "endwith": //????,??
  239. str="";
  240. var ends = option["endwith"].split(",");
  241. for(var v in ends){
  242. str+=ends[v]+"|";
  243. }
  244. str = str.substring(0,str.length-1);
  245. reg = new RegExp("^.*(?:"+str+")$","i");
  246. break;
  247. }
  248. }else if(type=="number"){ //??
  249. switch(limits){
  250. case "min":
  251. result = parseFloat(option["min"])<=parseFloat(value);
  252. break;
  253. case "max":
  254. result = parseFloat(option["max"])>=parseFloat(value);
  255. break;
  256. case "enum":
  257. var enums = option["enum"].split(",");
  258. for(var v in enums){
  259. if(parseFloat(enums[v])==parseFloat(value)){ // ??? ?????????
  260. result = true;
  261. return;
  262. }
  263. }
  264. break;
  265. case "except":
  266. var excepts = option["except"].split(",");
  267. var b = true;
  268. for(var v in excepts){
  269. if(parseFloat(excepts[v])==parseFloat(value)){ // ??? ?????????
  270. b = false;
  271. return;
  272. }
  273. }
  274. result = b;
  275. break;
  276. case "format": //???? ?? ???
  277. var format = option["format"];
  278. format = format.split(".");
  279. //???? ?? ??? '*'??
  280. var zheng = format[0]!="*"?"[1-9]\\d{"+(format[0].length-1)+"}":"*";
  281. zheng = format[0].length<2?(format[0]=="*"?"0|[1-9]\\d*":"\\d"):zheng;
  282. var fu ="{0}";
  283. fu =format.length==2?(format[1]=="*"?"*":"{"+format[1].length+"}"):fu;
  284. reg =fu==0?new RegExp("^[+\\-]?"+zheng+"$"):new RegExp("^[+\\-]?"+zheng+"\\.\\d"+fu+"$");
  285. break;
  286. }
  287. }else{ //??
  288. var sr = JSValidator.Tools.GetDateFromStr(value);
  289. var b = false;
  290. switch(limits){
  291. case "min":
  292. var min = JSValidator.Tools.GetDateFromStr(option["min"]);
  293. b = (!(min>sr))&&(!(min<sr));
  294. result = (sr>min||b==true);
  295. break;
  296. case "max":
  297. var max = JSValidator.Tools.GetDateFromStr(option["max"]);
  298. b = (!(max>sr))&&(!(max<sr));
  299. result = (sr<max||b==true);
  300. break;
  301. case "enum":
  302. b = false;
  303. enums = option["enum"].split(",");
  304. for(var v in enums){
  305. var date = JSValidator.Tools.GetDateFromStr(enums[v]);
  306. b = (!(date>sr))&&(!(date<sr));
  307. if(b==true){
  308. b= true;
  309. break;
  310. }
  311. }
  312. result= b;
  313. break;
  314. case "except":
  315. b = true;
  316. excepts = option["except"].split(",");
  317. for(var v in excepts){
  318. var date = JSValidator.Tools.GetDateFromStr(excepts[v]);
  319. b = (!(date>sr))&&(!(date<sr));
  320. b =!b;
  321. if(b==false){
  322. b = false;
  323. break;
  324. }
  325. }
  326. result = b;
  327. break;
  328. }
  329. }
  330. result = reg?reg.test(value):result;
  331. return result; //??????
  332. }
  333. }
  334. },
  335. /**????????????**/
  336. validateBean:function(){
  337. var _id = null; // ?????id
  338. var _for = null; // ????????? id
  339. var _rule = null; // ?? ???? ??
  340. var _pass = null; // ????? ?????
  341. var _error = null; // ????? ?????
  342. var _tips = null; // ?? ????? ?????
  343. var _empty = null; // ?? ????? ??????????
  344. var _require = "true"; // ?? ?? ???????
  345. var _to = null; // ?????? ????? id
  346. var _format = null; // ?????? ?????
  347. var _min = null; // ???????
  348. var _max = null; // ???????
  349. var _as = "string"; // ?? ??????string:??? number:?? date:???
  350. var _mode = "equal"; // ?????(=?>,<,!=,>=,<=)
  351. var _enum =null; // ???
  352. var _except =null; // ???
  353. var _expression=null; // ?????
  354. var _beginwith = null; //? ????
  355. var _endwith = null; //? ????
  356. //???? ???? ??????
  357. this.empty = _empty;
  358. this.tips = _tips;
  359. this.error = _error;
  360. this.pass = _pass;
  361. this.temp = "";
  362. this.limits = []; //?? ??????????
  363. this.getId=function(){return _id;}
  364. this.setId=function(p0){_id=p0;}
  365. this.getFor=function(){return _for;}
  366. this.setFor=function(p0){_for=p0;}
  367. this.getRule=function(){return _rule;}
  368. this.setRule=function(p0){_rule = p0;}
  369. this.getPass=function(){return _pass;}
  370. this.setPass=function(p0){_pass = p0;}
  371. this.getError=function(){return _error;}
  372. this.setError=function(p0){_error = p0;}
  373. this.getTips=function(){return _tips;}
  374. this.setTips=function(p0){_tips = p0;}
  375. this.getEmpty=function(){return _empty;}
  376. this.setEmpty=function(p0){_empty = p0;}
  377. this.getRequire=function(){return _require;}
  378. this.setRequire=function(p0){if(JSValidator.Tools.Exists(p0)){_require = p0;}}
  379. this.getTo=function(){return _to;}
  380. this.setTo=function(p0){_to = p0;}
  381. this.getFormat=function(){return _format;}
  382. this.setFormat=function(p0){_format = p0;}
  383. this.getMin=function(){return _min;}
  384. this.setMin=function(p0){_min = p0;}
  385. this.getMax=function(){return _max;}
  386. this.setMax=function(p0){_max = p0;}
  387. this.getAs=function(){return _as;}
  388. this.setAs=function(p0){_as = p0;}
  389. this.getMode=function(){return _mode;}
  390. this.setMode=function(p0){_mode = p0;}
  391. this.getEnum=function(){return _enum;}
  392. this.setEnum=function(p0){_enum = p0;}
  393. this.getExcept=function(){return _except;}
  394. this.setExcept=function(p0){_except = p0;}
  395. this.getExpression=function(){return _expression;}
  396. this.setExpression=function(p0){_expression = p0;}
  397. this.getBeginwith=function(){return _beginwith;}
  398. this.setBeginwith=function(p0){_beginwith = p0;}
  399. this.getEndwith=function(){return _endwith;}
  400. this.getEndwith=function(p0){_endwith = p0;}
  401. //??????
  402. this.initTag=function(tag){
  403. _id = JSValidator.Tools.Exists(tag.getAttribute("id"))?tag.getAttribute("id"):_id;
  404. _for = JSValidator.Tools.Exists(tag.getAttribute("for"))?tag.getAttribute("for"):_for;
  405. _rule = JSValidator.Tools.Exists(tag.getAttribute("rule"))?tag.getAttribute("rule"):_rule;
  406. _pass = JSValidator.Tools.Exists(tag.getAttribute("pass"))?tag.getAttribute("pass"):_pass;
  407. _error = JSValidator.Tools.Exists(tag.getAttribute("error"))?tag.getAttribute("error"):_error;
  408. _tips = JSValidator.Tools.Exists(tag.getAttribute("tips"))?tag.getAttribute("tips"):_tips;
  409. _empty = JSValidator.Tools.Exists(tag.getAttribute("empty"))?tag.getAttribute("empty"):_empty;
  410. _require = JSValidator.Tools.Exists(tag.getAttribute("require"))?tag.getAttribute("require"):_require;
  411. _to = JSValidator.Tools.Exists(tag.getAttribute("to"))?tag.getAttribute("to"):_to;
  412. _as = JSValidator.Tools.Exists(tag.getAttribute("as"))?tag.getAttribute("as"):_as;
  413. _mode = JSValidator.Tools.Exists(tag.getAttribute("mode"))?tag.getAttribute("mode"):_mode;
  414. _min =JSValidator.Tools.Exists(tag.getAttribute("min"))?tag.getAttribute("min"):_min;
  415. _max = JSValidator.Tools.Exists(tag.getAttribute("max"))?tag.getAttribute("max"):_max;
  416. _enum = JSValidator.Tools.Exists(tag.getAttribute("enum"))?tag.getAttribute("enum"):_enum;
  417. _except =JSValidator.Tools.Exists(tag.getAttribute("except"))?tag.getAttribute("except"):_except;
  418. _format = JSValidator.Tools.Exists(tag.getAttribute("format"))?tag.getAttribute("format"):_format;
  419. _beginwith =JSValidator.Tools.Exists(tag.getAttribute("beginwith"))?tag.getAttribute("beginwith"):_beginwith;
  420. _endwith =JSValidator.Tools.Exists(tag.getAttribute("endwith"))?tag.getAttribute("endwith"):_endwith;
  421. _expression =JSValidator.Tools.Exists(tag.getAttribute("expression"))?tag.getAttribute("expression"):_expression;
  422. this.empty = _empty;
  423. this.tips = _tips;
  424. this.error = _error;
  425. this.pass = _pass;
  426. this.temp = "";
  427. this.limits["min"] = _min;
  428. this.limits["max"] = _max;
  429. this.limits["enum"] = _enum;
  430. this.limits["except"] = _except;
  431. this.limits["beginwith"] = _beginwith;
  432. this.limits["endwith"] = _endwith;
  433. this.limits["format"] = _format;
  434. //......
  435. }
  436. }
  437. };
  438. /**
  439. *?? ??????
  440. **/
  441. //#---class JSValidator.Tools start--#//
  442. JSValidator.Tools={
  443. //?????ID???????
  444. $:function(id){return document.getElementById(id);},
  445. //???? ?????????
  446. Exists:function(obj){
  447. if(typeof(obj)=='undefined'||obj==null){
  448. return false;
  449. }else{
  450. return true;
  451. }
  452. },
  453. //????? ???????????
  454. InsertAfter:function(newElement,targetElement){
  455. var parent = targetElement.parentNode;
  456. if(parent.lastChild == targetElement){
  457. parent.appendChild(newElement);
  458. }else{
  459. parent.insertBefore(newElement,targetElement.nextSibling);
  460. }
  461. },
  462. //? ??????????? ??
  463. AddEventFunc:function(obj,eve,func,param){
  464. var oldfunc = obj[eve];
  465. if(typeof obj[eve] !='function'){
  466. obj[eve] = function(event){
  467. event=window.event||event;
  468. func(event.srcElement?event.srcElement:event.target,param);
  469. return JSValidator.validateForm.submit;
  470. }
  471. }else{
  472. obj[eve] = function(event){
  473. event=window.event||event;
  474. oldfunc(event.srcElement?event.srcElement:event.target,param);
  475. func(event.srcElement?event.srcElement:event.target,param);
  476. return JSValidator.validateForm.submit;
  477. }
  478. }
  479. },
  480. //??? ??????? ?????Date??
  481. GetDateFromStr:function(dateStr){
  482. var datetime=null;
  483. var d = dateStr.split(" ");
  484. if(d.length>1){
  485. t = d[1].split(":");
  486. d = d[0].split("-");
  487. datetime = new Date(d[0],d[1],d[2],t[0],t[1],t[2]);
  488. }else{
  489. d = dateStr.split("-");
  490. datetime = new Date(d[0],d[1],d[2]);
  491. }
  492. return datetime;
  493. }
  494. };//#---class JSValidator.Tools end--#//
  495. /**
  496. *??? ?????
  497. */
  498. //#---class JSValidator.Core start--#//
  499. JSValidator.Core={
  500. /**?? ?????????????????? **/
  501. validate:function(formElement,operate){
  502. //?? ???????
  503. var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
  504. // ???tag?? ??? Bean
  505. var Bean = new JSValidator.validateBean();
  506. Bean.initTag(tag);
  507. //JSValidator.validateForm.submit=true;
  508. /**** ?? ?????????***/
  509. // rule?? ??? ????? ?
  510. if(operate==""){
  511. // ?? ????? ?????
  512. if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
  513. if(Bean.getRequire()=="true"){ //???????
  514. JSValidator.Message.Show(Bean,"empty");
  515. JSValidator.validateForm.submit=false;
  516. }else{ //??? ?????
  517. JSValidator.Message.Show(Bean,"temp");
  518. }
  519. }else if(!(JSValidator.regulation.simple[Bean.getRule()].test(formElement.value))){
  520. JSValidator.Message.Show(Bean,"error");
  521. JSValidator.validateForm.submit=false;
  522. }else{
  523. JSValidator.Message.Show(Bean,"pass");
  524. }
  525. }
  526. // rule?? ?? ????? ?
  527. else if(operate=="||"||operate=="&&"){
  528. var rules = Bean.getRule().split(operate);
  529. var b = false;
  530. for(var i=0;i<rules.length;i++){
  531. if(rules[i]!="limit"){ //??? ????
  532. // ? ?? ??
  533. if(operate=="||"){
  534. b = false;
  535. b = JSValidator.regulation.simple[rules[i]].test(formElement.value)?true:false;
  536. if(b==true){
  537. break;
  538. }
  539. }
  540. // ? ?? ??
  541. else if(operate=="&&"){
  542. b = true;
  543. b = JSValidator.regulation.simple[rules[i]].test(formElement.value)?true:false;
  544. if(b==false){
  545. break;
  546. }
  547. }
  548. }else{ //??? ???? ? limit ??
  549. // ? ?? ??
  550. if(operate=="||"){
  551. b = false;
  552. b = JSValidator.regulation.complex.limit(formElement.value,Bean)?true:false;
  553. alert(b);
  554. if(b==true){
  555. break;
  556. }
  557. }
  558. // ? ?? ??
  559. else if(operate=="&&"){
  560. b = true;
  561. b = JSValidator.regulation.complex.limit(formElement.value,Bean)?true:false;
  562. if(b==false){
  563. break;
  564. }
  565. }
  566. }
  567. }
  568. if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
  569. if(Bean.getRequire()=="true"){ //???????
  570. JSValidator.Message.Show(Bean,"empty");
  571. JSValidator.validateForm.submit=false;
  572. }else{ //??? ?????
  573. JSValidator.Message.Show(Bean,"temp");
  574. }
  575. }else if(!b){
  576. JSValidator.Message.Show(Bean,"error");
  577. JSValidator.validateForm.submit=false;
  578. }else{
  579. JSValidator.Message.Show(Bean,"pass");
  580. }
  581. }
  582. },
  583. /**? ???? ????**/
  584. valForCompare:function(formElement){
  585. //?? ???????
  586. var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
  587. // ???tag?? ??? Bean
  588. var Bean = new JSValidator.validateBean();
  589. //JSValidator.validateForm.submit=true;
  590. Bean.initTag(tag);
  591. var sourceValue = JSValidator.Tools.$(Bean.getFor()).value;
  592. var targetValue = JSValidator.Tools.$(Bean.getTo()).value;
  593. if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
  594. if(Bean.getRequire()=="true"){ //???????
  595. JSValidator.Message.Show(Bean,"empty");
  596. JSValidator.validateForm.submit=false;
  597. }else{ //??? ?????
  598. JSValidator.Message.Show(Bean,"temp");
  599. }
  600. }else if(!(JSValidator.regulation.complex.compare(sourceValue,targetValue,Bean.getAs(),Bean.getMode()))){
  601. JSValidator.Message.Show(Bean,"error");
  602. JSValidator.validateForm.submit=false;
  603. }else{
  604. JSValidator.Message.Show(Bean,"pass");
  605. }
  606. },
  607. /***??????? ????? ?????**/
  608. valForCustom:function(formElement){
  609. //?? ???????
  610. var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
  611. // ???tag?? ??? Bean
  612. var Bean = new JSValidator.validateBean();
  613. Bean.initTag(tag);
  614. //JSValidator.validateForm.submit=true;
  615. if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
  616. if(Bean.getRequire()=="true"){ //???????
  617. JSValidator.Message.Show(Bean,"empty");
  618. JSValidator.validateForm.submit=false;
  619. }else{ //??? ?????
  620. JSValidator.Message.Show(Bean,"temp");
  621. }
  622. }else if(!(JSValidator.regulation.complex.custom(formElement.value,Bean.getExpression()))){
  623. JSValidator.Message.Show(Bean,"error");
  624. JSValidator.validateForm.submit=false;
  625. }else{
  626. JSValidator.Message.Show(Bean,"pass");
  627. }
  628. },
  629. valForLimit:function(formElement){
  630. //?? ???????
  631. var tag = JSValidator.Tools.$(formElement.getAttribute("tagid"));
  632. // ???tag?? ??? Bean
  633. var Bean = new JSValidator.validateBean();
  634. Bean.initTag(tag);
  635. //JSValidator.validateForm.submit=true;
  636. if(!(JSValidator.regulation.simple["notempty"].test(formElement.value))){
  637. if(Bean.getRequire()=="true"){ //???????
  638. JSValidator.Message.Show(Bean,"empty");
  639. JSValidator.validateForm.submit=false;
  640. }else{ //??? ?????
  641. JSValidator.Message.Show(Bean,"temp");
  642. }
  643. }else if(!(JSValidator.regulation.complex.limit(formElement.value,Bean))){
  644. JSValidator.Message.Show(Bean,"error");
  645. JSValidator.validateForm.submit=false;
  646. }else{
  647. JSValidator.Message.Show(Bean,"pass");
  648. }
  649. }
  650. };//#---class JSValidator.Core end--#//
  651. /**
  652. *??? ???
  653. */
  654. JSValidator.Message={
  655. MsgCss:{
  656. empty:"msg_error",
  657. pass:"msg_ok",
  658. error:"msg_error",
  659. tips:"msg_tips",
  660. temp:""
  661. },
  662. /**?????????
  663. tagBean - ???????????? (JSValidator.validateBean)
  664. msgContent-?????????? ??empty,error,pass,tips?,
  665. **/
  666. Show:function(tagBean,msgContent){
  667. var span = null; // span ???
  668. var spanid = "JSValidator"+tagBean.getFor()+tagBean.getId()+""; // span ????id
  669. if(JSValidator.Tools.$(spanid)){ // ?? ???????
  670. span= JSValidator.Tools.$(spanid); // ?? span??
  671. }else{
  672. span = document.createElement("span"); // ?? ??????
  673. span.id= spanid; // ?? id
  674. JSValidator.Tools.InsertAfter(span,JSValidator.Tools.$(tagBean.getFor())); //??????????????
  675. }
  676. span.innerHTML = tagBean[msgContent]!=null? tagBean[msgContent]:""; // ??????
  677. span.className = this.MsgCss[msgContent]; // ??????
  678. },
  679. //????????????????????????
  680. Remove:function(){
  681. }
  682. };
  683. var ValidateFactory={
  684. GetValidateField:function(tagItem,iterateCount){
  685. //??????????? id
  686. tagItem.setAttribute("id","mytagelement"+iterateCount);
  687. //??? ??id?? ????????????????
  688. JSValidator.Tools.$(tagItem.getAttribute("for")).setAttribute("tagid","mytagelement"+iterateCount);
  689. //??? ?? ??????? ??? Bean
  690. var formBean = new JSValidator.validateBean();
  691. formBean.initTag(tagItem);
  692. if(!JSValidator.Tools.Exists(formBean.getRule())){
  693. throw new Error("????????rule??????");
  694. return false;
  695. }
  696. /**????tips??????? onfocus??**/
  697. if(JSValidator.Tools.Exists(formBean.getTips())){
  698. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onfocus",JSValidator.tipuser,"temp_param");
  699. }
  700. var s1 = formBean.getRule().indexOf("||");
  701. var s2 = formBean.getRule().indexOf("&&");
  702. /**???? ?????? ? ????? ????**/
  703. if((s1!=-1)||(s2!=-1)){ //???????????
  704. if(formBean.getRule().indexOf("compare")!=-1){
  705. throw new Error("rule??????????'copare'????????????rule????");
  706. return false;
  707. }else if(formBean.getRule().indexOf("custom")!=-1){
  708. throw new Error("rule??????????'custom'????????????rule????");
  709. return false;
  710. }else if(s1!=-1&&s2!=-1){
  711. throw new Error("rule???????????????? ????????rule????");
  712. return false;
  713. }else{
  714. var operate = s1!=-1?"||":"&&"; //?????
  715. /***????????? ?????? onblur??****/
  716. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.validate,operate);
  717. }
  718. }
  719. else{//?? ?? ? ?????? ??
  720. switch(formBean.getRule()){
  721. case "limit":
  722. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForLimit,"");
  723. break;
  724. case "compare":
  725. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForCompare,"");
  726. break;
  727. case "custom":
  728. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.valForCustom,"");
  729. break;
  730. default :
  731. JSValidator.Tools.AddEventFunc(JSValidator.Tools.$(formBean.getFor()),"onblur",JSValidator.Core.validate,"");
  732. break;
  733. }
  734. }
  735. }
  736. };
  737. /**
  738. *??????
  739. */
  740. JSValidator.Exception=function(message){
  741. alert(">>???????:\n\t????:"+message);
  742. };
  743. //-->