Skip to content

Instantly share code, notes, and snippets.

@nosrednawall
Last active June 4, 2018 13:53
Show Gist options
  • Save nosrednawall/904e4a70e2ad1ff332a60ac3d937c8c3 to your computer and use it in GitHub Desktop.
Save nosrednawall/904e4a70e2ad1ff332a60ac3d937c8c3 to your computer and use it in GitHub Desktop.
Validador regex para cpf e cnpj, apenas para quantidade de caracteres
<p:outputLabel value="Cpf/CNPJ " for="cpf" />
<p:inputText id="cpf" value="#{seuBean.entitade.cpfCnpj}"
maxlength="20" required="true"
requiredMessage="Campo cpf não pode estar em branco"
validatorMessage="CPF inválido">
<f:passThroughAttribute name="placeholder" value="Informe o seu CPF ou CNPJ" />
<f:validateRegex
pattern="([0-9]{2}[\.]?[0-9]{3}[\.]?[0-9]{3}[\/]?[0-9]{4}[-]?[0-9]{2})|([0-9]{3}[\.]?[0-9]{3}[\.]?[0-9]{3}[-]?[0-9]{2})" />
<f:ajax event="blur" render="messageCpf" />
<p:message for="cpf" id="messageCpf" />
</p:inputText>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment