JSF <f:validateRegex> Tag

It is used to check whether the local value of a component is a match against a regular expression from the java.util.regex package or not.

# Tag Attributes

Attribute Description
pattern It is used to set a regular expression pattern for the component. It is a required attribute.

# JSF <f:validateRegex> Tag Example

// index.xhtml


<h:form id="form">
<h:outputLabel for="username">User Name</h:outputLabel>
<h:inputText id="name-id" value="#{user.name}" validatorMessage="Your name can have only Alphabets">
<f:validateRegex pattern="^([a-zA-Z]+(.)?[\s]*)$" />
</h:inputText><br/>
<h:commandButton value="OK" action="response.xhtml"></h:commandButton>
</h:form>

// User.java


import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class User{
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

Output:

JSF F valiregex tag 1