How can i make sure at conversion and validation phase during the JSF lifecycle that entered value in <h:inputText> contains alphabets only?
Thanks in advance.
You can use <f:validateRegex> for this.
<h:inputText id="input" value="#{bean.input}" validatorMessage="Please enter alphabets only">
<f:validateRegex pattern="[a-zA-Z]*" />
</h:inputText>
It accepts the same regex syntax as the Pattern class. Check its documentation. You can also use \p{Alpha} instead.
<f:validateRegex pattern="\\p{Alpha}*" />
Or if you're using bean validation (as confirmed by your question history), then you can also use @Pattern for this.
@Pattern(regexp="\\p{Alpha}*", message="Please enter alphabets only")
private String input;
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