代码如下:
public abstract class BaseValidator extends Validator{ /** * 常用正则表达式:匹配非负整数(正整数 + 0) */ public static final String regExp_integer_1 = "^\\d+$"; /** * 常用正则表达式:匹配正整数 */ public static final String regExp_integer_2 = "^[0-9]*[1-9][0-9]*$"; /** * 常用正则表达式:匹配非正整数(负整数 + 0) */ public static final String regExp_integer_3 = "^((-\\d+) ?(0+))$"; /** * 常用正则表达式:匹配负整数 */ public static final String regExp_integer_4 = "^-[0-9]*[1-9][0-9]*$"; /** * 常用正则表达式:匹配整数 */ public static final String regExp_integer_5 = "^-?\\d+$"; /** * 常用正则表达式:匹配非负浮点数(正浮点数 + 0) */ public static final String regExp_float_1 = "^\\d+(\\.\\d+)?$"; /** * 常用正则表达式:匹配正浮点数 */ public static final String regExp_float_2 = "^(([0-9]+\\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]*\\.[0-9]+) ?([0-9]*[1-9][0-9]*))$"; /** * 常用正则表达式:匹配非正浮点数(负浮点数 + 0) */ public static final String regExp_float_3 = "^((-\\d+(\\.\\d+)?) ?(0+(\\.0+)?))$"; /** * 常用正则表达式:匹配负浮点数 */ public static final String regExp_float_4 = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*) ?([0-9]*[1-9][0-9]*\\.[0-9]+) ?([0-9]*[1-9][0-9]*)))$"; /** * 常用正则表达式:匹配浮点数 */ public static final String regExp_float_5 = "^(-?\\d+)(\\.\\d+)?$"; /** * 常用正则表达式:匹配由26个英文字母组成的字符串 */ public static final String regExp_letter_1 = "^[A-Za-z]+$"; /** * 常用正则表达式:匹配由26个英文字母的大写组成的字符串 */ public static final String regExp_letter_2 = "^[A-Z]+$"; /** * 常用正则表达式:匹配由26个英文字母的小写组成的字符串 */ public static final String regExp_letter_3 = "^[a-z]+$"; /** * 常用正则表达式:匹配由数字和26个英文字母组成的字符串 */ public static final String regExp_letter_4 = "^[A-Za-z0-9]+$"; /** * 常用正则表达式:匹配由数字、26个英文字母或者下划线组成的字符串 */ public static final String regExp_letter_5 = "^\\w+$"; /** * 常用正则表达式:匹配email地址 */ public static final String regExp_email = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$"; /** * 常用正则表达式:匹配url */ public static final String regExp_url_1 = "^[a-zA-z]+://(\\w+(-\\w+)*)(\\.(\\w+(-\\w+)*))*(\\?\\S*)?$"; /** * 常用正则表达式:匹配url */ public static final String regExp_url_2 = "[a-zA-z]+://[^\\s]*"; /** * 常用正则表达式:匹配中文字符 */ public static final String regExp_chinese_1 = "[\\u4e00-\\u9fa5]"; /** * 常用正则表达式:匹配双字节字符(包括汉字在内) */ public static final String regExp_chinese_2 = "[^\\x00-\\xff]"; /** * 常用正则表达式:匹配空行 */ public static final String regExp_line = "\\n[\\s ? ]*\\r"; /** * 常用正则表达式:匹配HTML标记 */ public static final String regExp_html_1 = "/ <(.*)>.* <\\/\\1> ? <(.*) \\/>/"; /** * 常用正则表达式:匹配首尾空格 */ public static final String regExp_startEndEmpty = "(^\\s*) ?(\\s*$)"; /** * 常用正则表达式:匹配帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线) */ public static final String regExp_accountNumber = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$"; /** * 常用正则表达式:匹配国内电话号码,匹配形式如 0511-4405222 或 021-87888822 */ public static final String regExp_telephone = "\\d{3}-\\d{8} ?\\d{4}-\\d{7}"; /** * 常用正则表达式:腾讯QQ号, 腾讯QQ号从10000开始 */ public static final String regExp_qq = "[1-9][0-9]{4,}"; /** * 常用正则表达式:匹配中国邮政编码 */ public static final String regExp_postcode = "[1-9]\\d{5}(?!\\d)"; /** * 常用正则表达式:匹配身份证, 中国的身份证为15位或18位 */ public static final String regExp_idCard = "\\d{15} ?\\d{18}"; /** * 常用正则表达式:IP */ public static final String regExp_ip = "\\d+\\.\\d+\\.\\d+\\.\\d+"; /** * 常用正则表达式:手机号 */ public static final String regExp_mobile = "^0?(13[0-9]|15[012356789]|18[01236789]|14[57])[0-9]{8}$"; /** * 验证手机号 */ protected void validateMobile(String field, String errorKey, String errorMessage) { validateRegex(field, regExp_mobile, false, errorKey, errorMessage); } /** * 验证邮编 */ protected void validatePostcode(String field, String errorKey, String errorMessage) { validateRegex(field, regExp_postcode, false, errorKey, errorMessage); } /** * 验证身份证 */ protected void validateIdCard(String field, String errorKey, String errorMessage) { validateRegex(field, regExp_idCard, false, errorKey, errorMessage); } }
错误信息:
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:724)
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:531)
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:355)
at sun.reflect.annotation.AnnotationParser.parseAnnotation2(AnnotationParser.java:286)
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:120)
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:72)
at java.lang.reflect.Executable.declaredAnnotations(Executable.java:599)
at java.lang.reflect.Executable.declaredAnnotations(Executable.java:597)
at java.lang.reflect.Executable.getAnnotation(Executable.java:570)
at java.lang.reflect.Method.getAnnotation(Method.java:622)
at com.jfinal.aop.InterceptorManager.doBuild(InterceptorManager.java:83)
at com.jfinal.aop.InterceptorManager.buildControllerActionInterceptor(InterceptorManager.java:75)
at com.jfinal.core.ActionMapping.buildActionMapping(ActionMapping.java:86)
at com.jfinal.core.JFinal.initActionMapping(JFinal.java:102)
at com.jfinal.core.JFinal.init(JFinal.java:66)
at com.jfinal.core.JFinalFilter.init(JFinalFilter.java:49)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4700)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5340)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1696)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:484)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:433)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468)
at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:323)
at sun.rmi.transport.Transport$1.run(Transport.java:200)
at sun.rmi.transport.Transport$1.run(Transport.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)