本文整理匯總了Java中play.data.validation.Constraints類的典型用法代碼示例。如果您正苦於以下問題:Java Constraints類的具體用法?Java Constraints怎麽用?Java Constraints使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Constraints類屬於play.data.validation包,在下文中一共展示了Constraints類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sanitize
import play.data.validation.Constraints; //導入依賴的package包/類
private Http.Request sanitize(Http.Context ctx, JsonNode body) throws SanitizingException {
Http.Request request = SanitizingHelper.sanitizeOptional("uid", body, Long.class, Attrs.USER_ID, ctx.request());
Optional<String> email = SanitizingHelper.parse("email", body, String.class);
if (email.isPresent()) {
Constraints.EmailValidator validator = new Constraints.EmailValidator();
if (!validator.isValid(email.get())) {
throw new SanitizingException("bad email format");
}
request = request.addAttr(Attrs.EMAIL, email.get());
}
request = SanitizingHelper.sanitizeOptional("email", body, String.class, Attrs.EMAIL, request);
return request;
}
示例2: setEmail
import play.data.validation.Constraints; //導入依賴的package包/類
public void setEmail(String email) throws UserException {
if (!(new Constraints.EmailValidator().isValid(email))) {
throw new UserException("exceptions.usermanagement.email_format");
}
this.email = email;
}