How is the validation string whole or not using spring annotations?
** I want the test user input to be alphanumeric or integer using spring form annotations **
i have also tried this code.
@NotEmpty
@NumberFormat(style = Style.NUMBER)
@Length(min =11,max =11)
@Column(name="abc")
private String xyz;
@NumberFormat
annotation only applies to subclasses of java.lang.Number ( Integer , Float , Double , BigDecimal , etc.); so it won't work with strings. To do this, you may need to create a custom annotation that checks that the string contains only numbers.
Take a look at the following tutorial; it goes into great detail on how to create custom annotations and use them for validation with Spring: http://softwarecave.org/2014/03/27/custom-bean-validation-constraints/
I faced a similar problem and used annotation @Pattern
to compare against regex.
@Pattern(regexp="^(0|[1-9][0-9]*)$")
The annotation is part of the package javax.validation.constraints
.