O'Reilly logo

PrimeFaces Beginner's Guide by K. Siva Prasad Reddy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Getting formatted input using the InputMask component

The InputMask component can be used to read input in a specific format. For example, we may want the user to enter a phone number in the XXX-XXX-XXXX format. We can use the <p:inputMask> component to read the input in the given format, restricting the user from entering invalid data:

<p:inputMask value="#{userController.registerUser.phone}" mask="999-999-9999"/>

The mask template can have the following characters, which have special meaning:

  • 9: Represents a single digit, that is from 0 to 9.
  • a: Represents an alphabetic character, that is from A to Z and a to z.
  • *: Represents any alphanumeric character, that is 0 to 9, A to Z, or a to z.

Let us see a few examples of mask templates:

<p:inputMask mask="(999) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required