How can i make sure at conversion and validation phase during the JSF lifecycle that entered value in <h:input开发者_开发知识库Text>
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;
精彩评论