**i want test user input is a alpha-numeric or integer by 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;
I ran into a similar problem and used the @Pattern
annotation to compare against a regular expression.
@Pattern(regexp="^(0|[1-9][0-9]*)$")
The annotation is part of the javax.validation.constraints
package.
The @NumberFormat
annotation only applies to subclasses of java.lang.Number (Integer, Float, Double, BigDecimal, etc.); therefore, it won't work with Strings. For this, you may have to create a custom annotation that validates the String only contains numbers.
Take a look at the following tutorial; it's very thorough on how to create custom annotations and use them for validation with Spring: http://softwarecave.org/2014/03/27/custom-bean-validation-constraints/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With