Phone.java 1.38 KB
package com.dituhui.pea.validated;


import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import javax.validation.Constraint;
import javax.validation.Payload;
import javax.validation.ReportAsSingleViolation;
import javax.validation.constraints.Null;
import javax.validation.constraints.Pattern;

import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;
import org.hibernate.validator.constraints.Length;

/**
 * 验证手机号,空和正确的手机号都能验证通过<br/>
 * 正确的手机号由11位数字组成,第一位为1
 * 第二位为 3、4、5、7、8
 *
 * @author zl
 */
@ConstraintComposition(CompositionType.OR)
@Pattern(regexp = "0?(13|14|15|17|18|19)[0-9]{9}")
@Null
@Length(min = 0, max = 0)
@Documented
@Constraint(validatedBy = {})
@Target({ METHOD, FIELD, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@ReportAsSingleViolation
public @interface Phone {

    String message();

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

}