InputMask component forces input to be formatted in a certain pattern.
<div class="card">
<div class="ui-fluid formgrid grid">
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Date" />
<p:inputMask id="date" value="#{maskView.date}" mask="99/99/9999" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Phone" />
<p:inputMask id="phone" value="#{maskView.phone}" mask="(999) 999-9999" validateMask="true" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Phone with Ext:" />
<p:inputMask id="phoneWithExt" value="#{maskView.phoneExt}" mask="(999) 999-9999[ x99999]" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Tax Id" />
<p:inputMask id="taxId" value="#{maskView.taxId}" mask="99-9999999" validateMask="true" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="SSN" />
<p:inputMask id="ssn" value="#{maskView.ssn}" mask="999-99-9999" validateMask="true" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Product Key" />
<p:inputMask id="key" value="#{maskView.productKey}" mask="a*-999-a999" validateMask="true" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="RTL" />
<p:inputMask id="rtl" value="#{maskView.rtl}" mask="999/99" dir="rtl" />
</div>
<div class="field col-12 md:col-4">
<p:outputLabel for="@next" value="Show On Focus" />
<p:inputMask id="hideonfocus" mask="99/99/9999" showMaskOnHover="false" />
</div>
<div class="field col-12 md:col-4">
<span class="ui-float-label" style="margin-top: 25px;">
<p:inputMask id="floatlabel" mask="99/99/9999" showMaskOnHover="false" />
<p:outputLabel for="@previous" value="Float Label" />
</span>
</div>
</div>
</div>
package org.primefaces.showcase.view.input;
import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@RequestScoped
@RegisterForReflection(serialization = true)
public class MaskView {
private String date;
private String phone;
private String phoneExt;
private String taxId;
private String ssn;
private String productKey;
private String rtl;
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPhoneExt() {
return phoneExt;
}
public void setPhoneExt(String phoneExt) {
this.phoneExt = phoneExt;
}
public String getTaxId() {
return taxId;
}
public void setTaxId(String taxId) {
this.taxId = taxId;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getProductKey() {
return productKey;
}
public void setProductKey(String productKey) {
this.productKey = productKey;
}
public String getRtl() {
return rtl;
}
public void setRtl(String rtl) {
this.rtl = rtl;
}
}