Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8242483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:11:05+00:00 2026-06-07T21:11:05+00:00

I would like to restrict the input in a inputText to Y or N.

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:11:06+00:00Added an answer on June 7, 2026 at 9:11 pm

    You can use validator as the user input too, this way:

    <p:inputText id="idfield" value="#{myBean.field}"
                    validatorMessage="Only Y or N">
                    <f:validateRegex pattern="[Y N]*" />
                    <p:ajax update="msg" event="keyup" />
                </p:inputText>
                <p:message for="idfield" id="msg" display="icon" />
    

    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:

     <p:selectOneRadio id="sor"
     value="#{myBean.value}">
     <f:selectItem itemLabel="Y" itemValue="Y" />
    <f:selectItem itemLabel="N" itemValue="N" />
    </p:selectOneRadio>
    

    With char(1) on database too. Works great.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use the following code to restrict input (to alphanumeric) into
I would like to restrict a column value in a table. For example, the
What I would like to do: restrict user input to letters only (lowercase and
I have a set of ints whose input I'd like to restrict. I would
I would like to validate and restrict newline/linefeed character. Valid XML: <root> <node>data data</node>
I would like to restrict users from inserting more than 3 records with color
I have a web folder that I would like to restrict access to via
My web application contains a text box for which I would like to restrict
I would like to restrict the contents of a TextBox to contain only five
I would like to restrict sending email to only a few addresses. My idea

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.