I would like to restrict the input in a inputText to Y or N. Following is what I thought of. Is this correct way or any better way is possible ?
<p:inputText value="#{myBean.field}" id="myID" title="Enter Y or N"
onkeypress ="if(!(event.keyCode == 89 || event.keyCode == 78)) event.keyCode=null;" />
<p:tooltip for="myID" showEvent="focus" hideEvent="blur" />
validateRegex can be used but I want to restrict the input as the user input the value and not on submit.
You can use validator as the user input too, this way:
I think you’ll solve your problem that way.
(You may have to change [Y N]* for [Y N] as i’m not sure about that *)
Nevertheless, in my apps I use, for Y or N, this:
With char(1) on database too. Works great.