Skip to content

Set of additional JSR 349 (formerly JSR 303) constraints and validators.

Notifications You must be signed in to change notification settings

gustavomoda/validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

Validation

This library provides a set of additional bean validation (JSR 349 formerly JSR 303) constraints and validators. You find the constraints in the package de.malkusch.validation.constraints:

  • @Age: The Date must be in the past and at least that years old.
  • @Adult: The Date must be at least 18 years old.
  • @BIC: The String must be a valid BIC (Business Identifier Code) address.
  • @IBAN: The String must be a valid IBAN (International Bank Account Number) address.
  • @BitcoinAddress: Validates a bitcoin address.
  • @TLD: The String is a Top Level Domain.
  • @Domain: The String has to be a Domain.
  • @IPv4: The String has to be an IPv4 address.
  • @ContentType: The Spring MultipartFile must match a ContentType. You have to provide javax.mail for the matching.
  • @Image: The Spring MultipartFile must be an image.
  • @NotEmptyBlob: The Blob must not be empty (but can be null).
  • @Country: The String has to be a well formed ISO-3166-1 alpha-2 country code.
  • @EqualProperties: The bean has properties with equal values (e.g. two identical passwords).
  • @ISBN: The String has to be an ISBN (International Standard Book Number).

Optional Dependencies

Some constraints require further dependencies. If you want to use them you have to provide those dependencies:

  • de.malkusch.validation.constraints.upload.* requires org.springframework.web and javax.mail.mail.

Additional Validators for JSR-349 built-ins

de.malkusch.validation.validator.jsr349 extends some JSR-349 built-in constraints with validators for additional types:

  • SizeValidatorForMultipartFile: Validates a @Size constraint against a Spring MultipartFile.
  • PastValidatorFor…: Validates a @Past constraint against java.time (JSR 310: Date and Time API) objects.
  • FutureValidatorFor…: Validates a @Future constraint against java.time (JSR 310: Date and Time API) objects.

If you want to use these validators you have to include the mapping resource META-INF/validation/mapping.xml. This can be done by preferably create the file META-INF/validation.xml and add that mapping or you do it programmatically with Configuration.addMapping(java.io.InputStream):

<?xml version="1.0" encoding="UTF-8"?>
<validation-config
    xmlns="https://jboss.org/xml/ns/javax/validation/configuration"
    xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://jboss.org/xml/ns/javax/validation/configuration validation-configuration-1.1.xsd">
    
    <constraint-mapping>META-INF/validation/mapping.xml</constraint-mapping>
</validation-config>

Maven

You find this package in Maven central:

<dependency>
    <groupId>de.malkusch.validation</groupId>
    <artifactId>validation</artifactId>
    <version>0.3.0</version>
</dependency>

About

Set of additional JSR 349 (formerly JSR 303) constraints and validators.

Resources

Stars

Watchers

Forks

Packages

No packages published