How to design a model class with validation NotNull,Size,NotBlank and pattern?

In this example we design a model class with validation to use NotNull,Size,NotBlank and pattern. NotBlank means there should be pass some message. Size means we pass length of message.

					import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

public class EmployeeDetail {
	@NotBlank(message = "empName should not be blank")
	@Size(min = 4, max = 20, message = "empName length should be between 4 and 20")
	@Pattern(regexp = "[a-zA-Z0-9]+$", message = "invalid empName no")
	private String empName;

Leave a Comment

Your email address will not be published. Required fields are marked *