I am validating my form field with given piece of code.
//controller method
public String addBusiness(@Valid @ModelAttribute("myForm") MyForm myForm, ...)
{
//logic will go here.
}
//form
@Component
public class MyForm{
@Pattern(regexp = "[0-9]{3,10}", message = "should be valid number")
public String getZip_code()
{
return this.zip_code;
}
}
Now I want same validation on zip_code
in another method of controller like,
@RequestMapping(value = "${validation.url}", method = RequestMethod.GET)
@ResponseBody
public List<String> getCityList(@RequestParam(value = "zip_code", required = true) final String zip_code)
{
//logic goes here
}
How is it possible?