how to restrict only letters and numbers at p:inputMask

Tonyukuk picture Tonyukuk · Apr 30, 2014 · Viewed 9.4k times · Source

I want to restrict my <p:inputMask> with only letters and numbers without giving any size (max-legth) limit. I tried to use mask attribute but when I use mask attriibute it gives a max-length for my inputMask. Could you please help me to solve this issue ?

Sample Code :

<p:inputMask value="#{gercekKrediBasvuruDetayGirisView.kisi.ticariHarfSeri}"
  required="true" mask="***" 
  requiredMessage="#{msg['GercekKrediBasvuruTuketiciMaliBilgiler.belgeSeriNull']}"
/>

Answer

Kuba picture Kuba · Apr 30, 2014

If your input does not have to be <p:inputMask> and can be <h:inputText> or <p:inputText> then the easiest way to go would be to use it with regex:

<h:inputText id="inputField" value="#{backingbean.username}" validatorMessage="Value does not match pattern.">
        <f:validateRegex pattern="^[a-zA-Z0-9]+$" />
</h:inputText>
<h:message for="inputField" />

If you only allow lower case letters go with ^[a-z0-9]+$. <p:inputMask> is designed for somewhat stricter validation than only letters and numbers.