javax.validation.constraints.Email Java Examples
The following examples show how to use
javax.validation.constraints.Email.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaxValidationModule.java From jsonschema-generator with Apache License 2.0 | 6 votes |
/** * Determine a given text type's format. * * @param member the field or method to check * @return specified format (or null) * @see Email */ protected String resolveStringFormat(MemberScope<?, ?> member) { if (member.getType().isInstanceOf(CharSequence.class)) { Email emailAnnotation = this.getAnnotationFromFieldOrGetter(member, Email.class, Email::groups); if (emailAnnotation != null) { // @Email annotation was found, indicate the respective format if (this.options.contains(JavaxValidationOption.PREFER_IDN_EMAIL_FORMAT)) { // the option was set to rather return the value for the internationalised email format return "idn-email"; } // indicate standard internet email address format return "email"; } } return null; }
Example #2
Source File: JavaxValidationModule.java From jsonschema-generator with Apache License 2.0 | 6 votes |
/** * Determine a given text type's pattern. * * @param member the field or method to check * @return specified pattern (or null) * @see Pattern */ protected String resolveStringPattern(MemberScope<?, ?> member) { if (member.getType().isInstanceOf(CharSequence.class)) { Pattern patternAnnotation = this.getAnnotationFromFieldOrGetter(member, Pattern.class, Pattern::groups); if (patternAnnotation != null) { // @Pattern annotation was found, return its (mandatory) regular expression return patternAnnotation.regexp(); } Email emailAnnotation = this.getAnnotationFromFieldOrGetter(member, Email.class, Email::groups); if (emailAnnotation != null && !".*".equals(emailAnnotation.regexp())) { // non-default regular expression on @Email annotation should also be considered return emailAnnotation.regexp(); } } return null; }
Example #3
Source File: ConstraintViolations.java From errors-spring-boot-starter with Apache License 2.0 | 5 votes |
private static Map<Class<? extends Annotation>, String> initErrorCodeMapping() { Map<Class<? extends Annotation>, String> codes = new HashMap<>(); // Standard Constraints codes.put(AssertFalse.class, "shouldBeFalse"); codes.put(AssertTrue.class, "shouldBeTrue"); codes.put(DecimalMax.class, "exceedsMax"); codes.put(DecimalMin.class, "lessThanMin"); codes.put(Digits.class, "tooManyDigits"); codes.put(Email.class, "invalidEmail"); codes.put(Future.class, "shouldBeInFuture"); codes.put(FutureOrPresent.class, "shouldBeInFutureOrPresent"); codes.put(Max.class, "exceedsMax"); codes.put(Min.class, "lessThanMin"); codes.put(Negative.class, "shouldBeNegative"); codes.put(NegativeOrZero.class, "shouldBeNegativeOrZero"); codes.put(NotBlank.class, "shouldNotBeBlank"); codes.put(NotEmpty.class, "shouldNotBeEmpty"); codes.put(NotNull.class, "isRequired"); codes.put(Null.class, "shouldBeMissing"); codes.put(Past.class, "shouldBeInPast"); codes.put(PastOrPresent.class, "shouldBeInPastOrPresent"); codes.put(Pattern.class, "invalidPattern"); codes.put(Positive.class, "shouldBePositive"); codes.put(PositiveOrZero.class, "shouldBePositiveOrZero"); codes.put(Size.class, "invalidSize"); // Hibernate Validator Specific Constraints codes.put(URL.class, "invalidUrl"); codes.put(UniqueElements.class, "shouldBeUnique"); codes.put(SafeHtml.class, "unsafeHtml"); codes.put(Range.class, "outOfRange"); codes.put(Length.class, "invalidSize"); return codes; }
Example #4
Source File: AccountsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * @param email An email. * @return The public keys of the account corresponding to the introduced email. */ @GetMapping("/public-keys") public AccountDto getAccountPublicKeys( @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { return accountsService.getAndCheckAccountPublicKeysByEmail(email); }
Example #5
Source File: SharedSecretsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Unshares a secret. * * @param secretId The secret ID of the secret to be unshared. * @param receiverEmail The email from which the secret will be unshared. * @return Object indicating if the execution was successful. */ @DeleteMapping("/sent/{secret-id}") public SuccessDto unshareSecret( @PathVariable(name = "secret-id", required = true) @NotNull UUID secretId, @RequestParam(name = "receiver-email") @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String receiverEmail) { sharedSecretsService.unshareSecret(sessionAccount.getAccountId(), secretId, receiverEmail); return new SuccessDto(true); }
Example #6
Source File: InvitationPendingActionsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Deletes an invitation pending action associated to a receiver email and a group ID. * * @param groupId The group ID. * @param receiverEmail The receiver email. * @return Object indicating if the execution was successful. */ @DeleteMapping("/group/{group-id}") public SuccessDto deleteInvitationPendingActionByGroupId( @PathVariable(name = "group-id", required = true) @NotNull UUID groupId, @RequestParam(name = "receiver-email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String receiverEmail) { invitationPendingActionsService.deleteInvitationPendingActionByGroupId(sessionAccount.getAccountId(), groupId, receiverEmail); return new SuccessDto(true); }
Example #7
Source File: InvitationPendingActionsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Deletes an invitation pending action associated to a receiver email and a secret ID. * * @param secretId The secret ID. * @param receiverEmail The receiver email. * @return Object indicating if the execution was successful. */ @DeleteMapping("/secret/{secret-id}") public SuccessDto deleteInvitationPendingActionBySecretId( @PathVariable(name = "secret-id", required = true) @NotNull UUID secretId, @RequestParam(name = "receiver-email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String receiverEmail) { invitationPendingActionsService.deleteInvitationPendingActionBySecretId(sessionAccount.getAccountId(), secretId, receiverEmail); return new SuccessDto(true); }
Example #8
Source File: SharedSecretsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Forgets a shared secret ex member. * * @param secretId The secret ID of the shared secret. * @param email The email of the ex member. * @return Object indicating if the execution was successful. */ @DeleteMapping("/sent/{secret-id}/ex-member") public SuccessDto forgetSharedSecretExMember( @PathVariable(name = "secret-id", required = true) @NotNull UUID secretId, @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { sharedSecretsService.forgetSharedSecretExMember(sessionAccount.getAccountId(), secretId, email); return new SuccessDto(true); }
Example #9
Source File: CommonController.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 5 votes |
@GetMapping("/emails/{email:.+}/checkEmail") @PermissionRequired public ResponseEntity<Result> getCheckEmail(@PathVariable("email") @Email String email, @RequestHeader("Authorization") String token) throws MessagingException { userService.checkEmail(email); userService.getCheckEmail(email, (int) AppContext.get().get(AuthConstant.USER_ID)); return ResponseEntity.ok().body(new Result<>("发送邮箱验证邮件成功")); }
Example #10
Source File: GroupsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Removes a participant from a group belonging to the current session account. * * @param groupId The group ID. * @param email Email of the participant to be removed from the group. * @return Object indicating if the execution was successful. */ @DeleteMapping("/{group-id}/participants") public SuccessDto removeParticipantFromGroup( @PathVariable(name = "group-id", required = true) @NotNull UUID groupId, @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { groupsService.removeParticipantFromGroup(sessionAccount.getAccountId(), groupId, email); return new SuccessDto(true); }
Example #11
Source File: GroupsController.java From guardedbox with GNU Affero General Public License v3.0 | 5 votes |
/** * Forgets a group ex member. * * @param groupId The group ID. * @param email The email of the ex member. * @return Object indicating if the execution was successful. */ @DeleteMapping("/{group-id}/ex-member") public SuccessDto forgetGroupExMember( @PathVariable(name = "group-id", required = true) @NotNull UUID groupId, @RequestParam(name = "email", required = true) @NotBlank @Email(regexp = EMAIL_PATTERN) @Size(min = EMAIL_MIN_LENGTH, max = EMAIL_MAX_LENGTH) String email) { groupsService.forgetGroupExMember(sessionAccount.getAccountId(), groupId, email); return new SuccessDto(true); }
Example #12
Source File: CommonController.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 5 votes |
@GetMapping("/emails/{email:.+}") public ResponseEntity<Result<Boolean>> checkEmail(@Email @NotBlank @PathVariable("email") String email) { if (userService.checkEmail(email)) { return ResponseEntity.status(HttpStatus.CONFLICT).body(new Result<>("邮箱已存在")); } return ResponseEntity.ok().body(new Result<>("邮箱不存在")); }
Example #13
Source File: User.java From crudui with Apache License 2.0 | 5 votes |
public User(@NotNull String name, @Past LocalDate birthDate, @NotNull int phoneNumber, @NotNull @Email String email,@NotNull BigDecimal salary, @NotNull @Size(min = 6, max = 100) String password, Boolean active, Group mainGroup, Set<Group> groups, MaritalStatus maritalStatus) { this.name = name; this.birthDate = birthDate; this.phoneNumber = phoneNumber; this.email = email; this.salary = salary; this.password = password; this.active = active; this.mainGroup = mainGroup; this.groups = groups; this.maritalStatus = maritalStatus; }
Example #14
Source File: CustomValueExtractorTest.java From hibernate-demos with Apache License 2.0 | 5 votes |
@Test public void shouldUseCustomValueExtractoe() { Customer bean = new Customer(); bean.emailsByType.put( "work", "[email protected]" ); bean.emailsByType.put( "work", "not-an-email" ); Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); Set<ConstraintViolation<Customer>> violations = validator.validate (bean ); assertEquals( 1, violations.size() ); ConstraintViolation<Customer> violation = violations.iterator().next(); assertEquals( "not-an-email", violation.getInvalidValue() ); assertEquals( Email.class, violation.getConstraintDescriptor().getAnnotation().annotationType() ); Iterator<Node> pathNodes = violation.getPropertyPath().iterator(); assertTrue( pathNodes.hasNext() ); Node node = pathNodes.next(); assertEquals( "emailsByType", node.getName() ); assertEquals( ElementKind.PROPERTY, node.getKind() ); assertTrue( pathNodes.hasNext() ); node = pathNodes.next(); assertEquals( "<multimap value>", node.getName() ); assertEquals( ElementKind.CONTAINER_ELEMENT, node.getKind() ); assertEquals( "work", node.getKey() ); assertFalse( pathNodes.hasNext() ); }
Example #15
Source File: EmailAnnotationPlugin.java From tutorials with MIT License | 5 votes |
/** * read Email annotation */ @Override public void apply(ModelPropertyContext context) { Optional<Email> email = annotationFromBean(context, Email.class); if (email.isPresent()) { context.getBuilder().pattern(email.get().regexp()); context.getBuilder().example("[email protected]"); } }
Example #16
Source File: SignupForm.java From semaphore-demo-java-spring with MIT License | 5 votes |
@JsonCreator public SignupForm( @JsonProperty("email") @Email @NotNull String email, @JsonProperty("password") @NotNull String password) { this.email = email; this.password = password; }
Example #17
Source File: EmailPostProcessor.java From RestDoc with Apache License 2.0 | 5 votes |
@Override public PropertyModel postProcessInternal(PropertyModel propertyModel) { Email emailAnno = propertyModel.getPropertyItem().getAnnotation(Email.class); if (emailAnno == null) return propertyModel; propertyModel.setDescription(TextUtils.combine(propertyModel.getDescription(), " (值为Email格式)")); return propertyModel; }
Example #18
Source File: NameCollisionDetectionTest.java From graphql-spqr with Apache License 2.0 | 4 votes |
@GraphQLQuery public List<@Email String> two() { return null; }
Example #19
Source File: Person.java From tutorials with MIT License | 4 votes |
public Person(int id, @NotBlank String username, @Email String email) { super(); this.id = id; this.username = username; this.email = email; }
Example #20
Source File: UserRestController.java From jakduk-api with MIT License | 4 votes |
@GetMapping("/exist/email") public EmptyJsonResponse existEmail(@NotEmpty @Email @ExistEmail @RequestParam String email) { return EmptyJsonResponse.newInstance(); }
Example #21
Source File: FeedbackController.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
@Email public String getEmail() { return email; }
Example #22
Source File: TestController.java From SpringAll with MIT License | 4 votes |
@GetMapping("test1") public String test1( @NotBlank(message = "{required}") String name, @Email(message = "{invalid}") String email) { return "success"; }
Example #23
Source File: CommonController.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 4 votes |
@GetMapping("/emails/{email:.+}/resetPasswordEmail") public ResponseEntity<Result> getResetPasswordEmail(@PathVariable("email") @Email String email) throws MessagingException { userService.getResetPasswordEmail(email); return ResponseEntity.ok().body(new Result<>("发送密码重置邮件成功")); }
Example #24
Source File: CommonController.java From Pixiv-Illustration-Collection-Backend with Apache License 2.0 | 4 votes |
@PutMapping("/{userId}/email") @CheckVerification public ResponseEntity<Result<User>> checkEmail(@RequestParam @Email String email, @PathVariable("userId") int userId, @RequestParam("vid") String vid, @RequestParam("value") String value) { User user = userService.setEmail(email, userId); return ResponseEntity.ok().header("Authorization", jwtUtil.getToken(user)).body(new Result<>("完成重置邮箱", user)); }
Example #25
Source File: DefaultModelPlugin.java From BlogManagePlatform with Apache License 2.0 | 4 votes |
private String resolveEmail(Field field) { return field.isAnnotationPresent(Email.class) ? "必须为合法的email" : null; }
Example #26
Source File: User.java From micronaut-data with Apache License 2.0 | 4 votes |
@Email public String getEmail() { return email; }
Example #27
Source File: SysDept.java From RuoYi-Vue with MIT License | 4 votes |
@Email(message = "邮箱格式不正确") @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") public String getEmail() { return email; }
Example #28
Source File: SysUser.java From RuoYi-Vue with MIT License | 4 votes |
@Email(message = "邮箱格式不正确") @Size(min = 0, max = 50, message = "邮箱长度不能超过50个字符") public String getEmail() { return email; }
Example #29
Source File: JavaxValidationModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@NotBlank(groups = Test.class) @Email(regexp = "^.+your-company\\.com$", groups = Test.class) public String getNonBlankOnGetterString() { return this.nonBlankOnGetterString; }
Example #30
Source File: JavaxValidationModuleTest.java From jsonschema-generator with Apache License 2.0 | 4 votes |
@NotEmpty(groups = Test.class) @Size(max = 100, groups = Test.class) @Email(groups = Test.class) public String getNonEmptyMaxSizeHundredOnGetterString() { return this.nonEmptyMaxSizeHundredOnGetterString; }