开发者

Validation problem for ensuring that entered value contains alphabet only

开发者 https://www.devze.com 2023-03-04 18:24 出处:网络
How can i make sure at conversion and validation phase during the JSF lifecycle that entered value in <h:input开发者_开发知识库Text> contains alphabets only?

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;
0

精彩评论

暂无评论...
验证码 换一张
取 消