Standard Validators in JSF
The input provided by the user must be validated before processing it to the next step. Like checking the contact number, name should contain only alphabets etc.

JSF has built-in validators that is used to perform different types of DataValidation. These validators are known as Standard Validators and the tags are provided by Core tag library in JSF.

Standard Validators


validateDoubleRange validateLongRange validateLength validateRequired validateRegex
Used to validate Range of double inputs Used to validate Range of Long inputs Used to validate Length Similar to required attribute of UI Component Used to validate input against specified pattern

When we use these validators and if the user input is wrong, the system will show an error message to the user which is of system format and user wont be able to understand. To overcome this we use ValidatorMessage to give the error message in understandable format for the user.

Lets get the input from User and validate it using the above Standard Validators
Name – Should contain only Alphabets and no numbers
phone – Should have 10 numbers
Amount- Should be between 200 and 5000
Credit Card – Required Field

JSF Managed Bean –

import javax.inject.Named;
import javax.enterprise.context.Dependent;
import javax.faces.bean.ManagedBean;

@Named(value = "customer")
public class Customer {
    String name,phone,amount,credit;

    public String getName() {
        return name;

    public void setName(String name) { = name;

    public String getPhone() {
        return phone;

    public void setPhone(String phone) { = phone;

    public String getAmount() {
        return amount;

    public void setAmount(String amount) {
        this.amount = amount;

    public String getCredit() {
        return credit;

    public void setCredit(String credit) { = credit;

    public Customer() {


<html xmlns=""
        <title>Standard Validators</title>
                    <td><h:outputLabel value="Enter the Username: "/></td>
                    <td><h:inputText value="#{}" required="true" validatorMessage="Enter only Alphabets for your name">
                            <c:validateRegex pattern="[a-zA-Z]*"/> //Regex for only Alphabets
                    <td><h:outputLabel value="Enter the phone: "/></td>
                    <td><h:inputText value="#{}" required="true" validatorMessage="10 numbers of your phone">
                <c:validateLength minimum="10" maximum="10"/> //minimum 10 numbers
                    <td><h:outputLabel value="Enter the Amount: "/></td>
                    <td><h:inputText value="#{customer.amount}" required="true" validatorMessage="Minimum is 200 and maximum is 5000 at Amount">
                <c:validateDoubleRange minimum="200" maximum="5000"/> //between 2 amounts
                    <td><h:outputLabel value="Credit Card Number: "/></td>
                    <td><h:inputText value="#{}" validatorMessage="Enter your Credit card number">
                <c:validateRequired/> //required field
                    <td colspan="3"><center><h:commandButton value="Validate" action="Input"/></center></td>




By Sri

Leave a Reply

Your email address will not be published. Required fields are marked *