目前内置了常见的几种类型:身份证号、手机号、固定电话、邮箱、IP地址
ID_CARD :身份证号 PHONE_NUM :手机号 FIXED_PHONE :固定电话 MAIL :邮箱 IP_ADDRESS: IP地址
@Data
@Accessors(chain = true)
public class IpEntity {
@Matcher(model = FieldModel.IP_ADDRESS)
private String ipValid;
@Matcher(model = FieldModel.IP_ADDRESS, accept =false)
private String ipInvalid;
}
def "IP测试"() {
given:
IpEntity entity = new IpEntity().setIpValid(valid).setIpInvalid(invalid)
expect:
boolean actResult = MkValidators.check(entity)
if (!result) {
println MkValidators.getErrMsgChain()
}
Assert.assertEquals(result, actResult)
where:
valid | invalid | result
"192.231asdf" | "192.123.231.222" | false
"192.231asdf" | "192.231asdf" | false
"192.123.231.222" | "192.231asdf" | true
"192.123.231.222" | "192.123.231.222" | false
}