页面JS的判断组件
<%@ page language="java" contentType="text/html; charset=utf-8"pageEncoding="utf-8"isELIgnored="false" %><%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><script type="text/javascript" src="<%=basePath%>js/Validator.js"></script></head><body><form action="" name="customerForm" method="post" ><table ><tr><td width="15%" height="20">企业名称:</td><td width="35%"><inputtype="text" name="corporate_name" value="" size="20" maxlength="40" dataType="Require"msg="企业名称不能为空"/><font color="red">*</font></td><td width="15%">编号:</td><td width="35%"><inputtype="text" name="contact_phone" value="" size="20" maxlength="12" require="false" dataType="Number" msg="请填写正确的数字编号"/><font color="red">*</font></td></tr><tr><td width="15%" height="20">下发电话:</td><td width="35%"><inputtype="text" name="send_sms_phone" value="" size="20" maxlength="12" require="false" dataType="Number" msg="请填写正确的手机号码,如:13810018008 "/></td><td width="15%">联系电话:</td><td width="35%"><inputtype="text" name="contact_phone" value="" size="20" maxlength="12" dataType="Phone" msg="请填写正确的联系电话,如:13810018008"/><font color="red">*</font></td></tr><tr align="left"><td colspan="4">&nbsp;</td></tr><tr> <td>&nbsp;</td> <td><input type="submit" name="sure" class="btn_2k3" value="提交"/> <input type="button" name="back" class="btn_2k3" value="返回"/></td> <td>&nbsp;</td> <td>&nbsp;</td></tr></table></body></html>Validator = {Require : /.+/,Email : /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,Phone : /^((\(\d{3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?\d{6,7}$/,Mobile : /^((\(\d{3}\))|(\d{3}\-))?13\d{9}$/,Url : /^http:\/\/+\.+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/,IdCard : /^\d{15}(\d{2})?$/,Currency : /^\d+(\.\d+)?$/,Number : /^\d+$/,Zip : /^\d{5}$/,QQ : /^\d{4,8}$/,Integer : /^[-\+]?\d+$/,Double : /^[-\+]?\d+(\.\d+)?$/,English : /^+$/,SafeAccount://,Chinese :/^[\u0391-\uFFE5]+$/,UnSafe : /^((*|*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\\\/\'\"]*)|.{0,5})$|\s/,IsSafe : function(str){return !this.UnSafe.test(str);},SafeString : "this.IsSafe(value)",Limit : "this.limit(value.length,getAttribute('min'),getAttribute('max'))",LimitB : "this.limit(this.LenB(value), getAttribute('min'), getAttribute('max'))",Date : "this.IsDate(value, getAttribute('min'), getAttribute('format'))",Repeat : "value == document.getElementsByName(getAttribute('to')).value",Range : "getAttribute('min') < value && value < getAttribute('max')",Compare : "this.compare(value,getAttribute('operator'),getAttribute('to'))",Custom : "this.Exec(value, getAttribute('regexp'))",Group : "this.MustChecked(getAttribute('name'), getAttribute('min'), getAttribute('max'))",ErrorItem : ],ErrorMessage : ["错误信息提示"],Validate : function(theForm, mode){var obj = theForm || event.srcElement;var count = obj.elements.length;this.ErrorMessage.length = 1;this.ErrorItem.length = 1;this.ErrorItem = obj;for(var i=0;i<count;i++){with(obj.elements){var _dataType = getAttribute("dataType");if(typeof(_dataType) == "object" || typeof(this) == "undefined")continue;this.ClearState(obj.elements);if(getAttribute("require") == "false" && value == "") continue;switch(_dataType){case "Date" :case "Repeat" :case "Range" :case "Compare" :case "Custom" :case "Group" : case "Limit" :case "LimitB" :case "SafeString" :if(!eval(this)){this.AddError(i, getAttribute("msg"));}break;default :if(!this.test(value)){this.AddError(i, getAttribute("msg"));}break;}}}if(this.ErrorMessage.length > 1){mode = mode || 1;var errCount = this.ErrorItem.length;switch(mode){case 2 :for(var i=1;i<errCount;i++)this.ErrorItem.style.color = "red";case 1 :alert(this.ErrorMessage.join("\n"));this.ErrorItem.focus();break;case 3 :for(var i=1;i<errCount;i++){try{var span = document.createElement("SPAN");span.id = "__ErrorMessagePanel";span.style.color = "red";this.ErrorItem.parentNode.appendChild(span);span.innerHTML = this.ErrorMessage.replace(/\d+:/,"*");}catch(e){alert(e.description);}}this.ErrorItem.focus();break;default :alert(this.ErrorMessage.join("\n"));break;}return false;}return true;},limit : function(len,min, max){min = min || 0;max = max || Number.MAX_VALUE;return min <= len && len <= max;},LenB : function(str){return str.replace(/[^\x00-\xff]/g,"**").length;},ClearState : function(elem){with(elem){if(style.color == "red")style.color = "";var lastNode = parentNode.childNodes;if(lastNode.id == "__ErrorMessagePanel")parentNode.removeChild(lastNode);}},AddError : function(index, str){this.ErrorItem = this.ErrorItem.elements;this.ErrorMessage = this.ErrorMessage.length + ":" + str;},Exec : function(op, reg){return new RegExp(reg,"g").test(op);},compare : function(op1,operator,op2){switch (operator) {case "NotEqual":return (op1 != op2);case "GreaterThan":return (op1 > op2);case "GreaterThanEqual":return (op1 >= op2);case "LessThan":return (op1 < op2);case "LessThanEqual":return (op1 <= op2);default:return (op1 == op2); }},MustChecked : function(name, min, max){var groups = document.getElementsByName(name);var hasChecked = 0;min = min || 1;max = max || groups.length;for(var i=groups.length-1;i>=0;i--)if(groups.checked) hasChecked++;return min <= hasChecked && hasChecked <= max;},IsDate : function(op, formatString){formatString = formatString || "ymd";var m, year, month, day;switch(formatString){case "ymd" :m = op.match(new RegExp("^((\\d{4})|(\\d{2}))([-./])(\\d{1,2})\\4(\\d{1,2})$"));if(m == null ) return false;day = m;month = m--;year =(m.length == 4) ? m : GetFullYear(parseInt(m, 10));break;case "dmy" :m = op.match(new RegExp("^(\\d{1,2})([-./])(\\d{1,2})\\2((\\d{4})|(\\d{2}))$"));if(m == null ) return false;day = m;month = m--;year = (m.length == 4) ? m : GetFullYear(parseInt(m, 10));break;default :break;}if(!parseInt(month)) return false;month = month==12 ?0:month;var date = new Date(year, month, day); return (typeof(date) == "object" && year == date.getFullYear() && month == date.getMonth() && day == date.getDate());function GetFullYear(y){return ((y<30 ? "20" : "19") + y)|0;}} }
页:
[1]