當前位置: 首頁>>代碼示例>>Java>>正文


Java Constraints類代碼示例

本文整理匯總了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;
}
 
開發者ID:CSCfi,項目名稱:exam,代碼行數:14,代碼來源:StudentEnrolmentSanitizer.java

示例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;
}
 
開發者ID:peerdavid,項目名稱:ComeAndGo,代碼行數:8,代碼來源:User.java


注:本文中的play.data.validation.Constraints類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。