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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:55:38+00:00 2026-06-16T08:55:38+00:00

I have a Edit-text in which user can enter amount, I want few limitations

  • 0

I have a Edit-text in which user can enter amount, I want few limitations on Edit-text

  1. Amount can not be greater than 100000
  2. User enter amount up to two decimal places like 99999.50

-EDITED- Solved

How do I achieve this, do I have to create a filter or I can achieve it using Regular Expression in myEdittext.addTextChangedListener(new TextWatcher() ...

myAmountEditText.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {}

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {}

            @Override
            public void afterTextChanged(Editable s) {
              if(amount!=null && amount.length()>=1 ){
                if(amount.contains(".")){
                    int indexOFdec =  amount.indexOf(".");

                    if(indexOFdec >=0) {
                       if(amount.substring(indexOFdec).length() >3){
                           amount = amount.substring(0, amount.length()-1);
                           myAmountEditText.setText(amount);
                           myAmountEditText.setSelection(myAmountEditText.getText().length());
                       }
                    }
                }

                Double a = Double.parseDouble(amount.toString());

                if(a>0 && a<100000.00){
                    //my stuff
                }else{
                    Toast.makeText(context, "amount greater than 100000", Toast.LENGTH_SHORT).show();
                }
            }
        });
  • 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-16T08:55:39+00:00Added an answer on June 16, 2026 at 8:55 am

    You can use this code:

    edittext.addTextChangedListener(new TextWatcher(){
        public void afterTextChanged(Editable s) {}
    
        public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    
        public void onTextChanged(CharSequence s, int start, int before, int count){
            String strEnteredVal = edittext.getText().toString();
    
            if(!strEnteredVal.equals("")){
            int num=Integer.parseInt(strEnteredVal);
            if(num<100000){
             edittext.setText(""+num);
            }else{
             edittext.setText("");
            }
        }
    
    }); 
    

    I think we can work for that like this:

    String str = editText.getText().toString();
    
        int indexOFdec =  str.indexOf(".");
    
        if(indexOFdec >=0) {
           if(str.substring(indexOFdec).length() >2)
           {
               Toast.makeText(getApplicationContext(), "Print a message here", Toast.LENGTH_SHORT).show();
               return;
           }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a edit text in which the user enters amount. What I want
I have a program which has a text box that the user can edit.
What I want I have an EditText, where the user can enter a value,
I have a text area in HTML where the user can enter text, but
I have an edit text which functions as a search box in my application.
I have a edittext in which some text are selected . I want to
I have an application that allows the user to edit multiple text fields and
I have a text file that I want to edit by rewriting it to
I have a setup view where the user can enter their name and email
I have an html box with which users may enter text. I would like

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.