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 4622170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:48:21+00:00 2026-05-22T02:48:21+00:00

My question is: I want the Text field in Eclipse RCP to allow only

  • 0

My question is:

I want the Text field in Eclipse RCP to allow only the digits to be keyed in as inputs and the requirement is that it should allow only up to ‘x’ (let’s say x=5) characters.
How can I accomplish it in RCP ?

I’ve tried the code like:

txtInput.addListener(SWT.Verify, new DecimalText(
                txtInsuranceValue, 8, 1000.00));

where txtInputis a Text field. But this listener failed when I made repeated input into this field at run time.

Any alternatives please ?

  • 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-05-22T02:48:21+00:00Added an answer on May 22, 2026 at 2:48 am

    This will set the maximum number of characters in your Text control to five and allow only digits to be entered:

        txtInput.setTextLimit(5);
    
        txtInput.addVerifyListener(new VerifyListener() {
            public void verifyText(VerifyEvent event) {
                // Assume we allow it
                event.doit = true;
    
                String text = event.text;
                char[] chars = text.toCharArray();
    
                //Don't allow if text contains non-digit characters
                for (int i = 0; i < chars.length; i++) {
                    if (!Character.isDigit(chars[i])) {
                        event.doit = false;
                        break;
                    }
                }
            }
        });
    

    EDIT: I’ve modified my answer to allow a user to also set text with “setText(String string)” while still disallowing non-digit characters.

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

Sidebar

Related Questions

Simple question, I just want to select the text from the <Template> tag. Here's
I want to take the information typed into a text field and display it
I have a text field that is expanding the entire horizontal distance to the
I have a text field that I'm searching against using an array of keywords
First let's explain what I want to do and then ask my question! Well,
I want to do some autosuggest for my text field, using this plugin AutoSuggest
I want to be able to set the color inside a Text Field to
When the user types in my text field, I want the first letter of
I wrote a validation code for an input text field, which will take only
I have a text field in my web app where I want to do

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.