jsfjsf-2jsf-1.2icefaces-1.8

How to validate regular expression when tab out in jsf/Icefaces


I want to validate a text field ( whether it contains special characters in the text) . I want to validate immediately when user tab out of the text field not on submit button. How to achive it using Icefaces 1.8 or JSF 1.2 ?

Below is the tag I have tried but it is working on submit button only

<f:validateRegex pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%]).{6,20})" />

Solution

  • You could move validation from jsf attribute to javascript. To do this you should add onblur attribute to your inputtext component as following :

    <h:inputText onblur="validate()">
    

    where validate() should be javascript method where you implement validation.