176
Spring MVC Regular Expression Validation
The Spring MVC Validation allows us to validate the user input in a particular sequence (i.e., regular expression). The @Pattern annotation is used to achieve regular expression validation. Here, we can provide the required regular expression to regexp attribute and pass it with the annotation.
Spring MVC Regular Expression Validation Example
1. Add dependencies to pom.xml file.
pom.xml
2. Create the bean class
Employee.java
3. Create the controller class
4. Provide the entry of controller in the web.xml file
web.xml
5. Define the bean in the xml file
spring-servlet.xml
6. Create the requested page
index.jsp
7. Create the other view components
viewpage.jsp
final.jsp
Output:
Next TopicNumber Validation