Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validation problem for ensuring that entered value contains alphabet only

Tags:

jsf

jsf-2

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.

like image 659
Adnan Avatar asked Dec 28 '25 16:12

Adnan


1 Answers

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;
like image 146
BalusC Avatar answered Dec 30 '25 15:12

BalusC