2

I'm looking to do an inputMask for an ip address.

Currently I have this code:

<p:inputMask value="#{newNode.ipv4}" mask="999.999.999.999">
       <p:keyFilter mask="num" /> 
</p:inputMask>

So I can enter un num value between 000.000.000.000 to 999.999.999.999 but I would like to restrict the input to 255.255.255.255, do you know a way to do this?

Thanks, Ersch

Ersch
  • 173
  • 2
  • 15

1 Answers1

4

Here you go:

<p:inputMask value="#{newNode.ipv4}" 
        mask="999.999.999.999" 
        validatorMessage="Invalid IPv4 Address">
    <f:validateRegex pattern="\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b"/>
</p:inputMask>
Max
  • 1,107
  • 12
  • 24
  • thanks for this one. It wasn't my first idea of how to solve it but it's very fine. So with this the validation is on the client side, if it fails, the action is not send? – Ersch Mar 31 '17 at 20:33
  • 2
    No, this is a server side validation, it is NOT an inputmask, so basically **not** an answer to your question, but as far as I know the only way it can work – Kukeltje Apr 01 '17 at 09:27