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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:45:55+00:00 2026-06-03T01:45:55+00:00

I am confused about the pattern used in my Regular Expression. What I want

  • 0

I am confused about the pattern used in my Regular Expression. What I want is before decimal the max no of digit the user want to enter is three and the digit should not start with zero. After entering the digit before decimal point which can be three-digit or two-digit or one-digit but can not start with zero. I want to allow users to enter one digit after the decimal point and it should be no more than one. So what will be the pattern for these?

Example:

Number Allow to enter: 1.3, 22.3, 333.4, 999.6

Number Not allowed to enter: 0, 0.1, .1, 4444.67, 333.78

Code I have Used

tempEditText.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(3,1)});
class DecimalDigitsInputFilter implements InputFilter
{
    Pattern mPattern;

    public DecimalDigitsInputFilter(int digitsBeforeZero, int digitsAfterZero)
    {
        mPattern = Pattern.compile("[0-9]{0," + (digitsBeforeZero - 1) + "}+((\\.[0-9]{0," + (digitsAfterZero - 1) + "})?)");
    }
    
    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
    {
        Matcher matcher = mPattern.matcher(dest);
        if(!matcher.matches())
        {
            return "";
        }
        return null;
    }
}
  • 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-03T01:45:57+00:00Added an answer on June 3, 2026 at 1:45 am

    I think that the pattern you want is:

    ^[1-9]\d{0,2}\.\d?$
    

    Explanation:

    ^        // Start of string
    [1-9]    // First digit can't be 0
    \d{0,2}  // Zero, one, or two more digits after first digit
    \.       // Literal decimal point
    \d?      // Optional single digit after decimal point
    $        // End of string
    

    In your code, it would be:

    mPattern = Pattern.compile("^[1-9]\\d{0," + (digitsBeforeZero - 1)
               + "}(\\.\\d{0," + digitsAfterZero + "})?$");
    

    The parentheses that you had around the decimal point and the trailing digit means that a number like “1.” would fail to match. Here’s a version that makes the decimal point required and the digit(s) afterwards optional:

    mPattern = Pattern.compile("^[1-9]\\d{0," + (digitsBeforeZero - 1)
               + "}\\.\\d{0," + digitsAfterZero + "}?$");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm really confused about the visitor pattern and its uses. I can't really seem
I am very confused about when I should use '\'. Consider the examples: (1)
I'm a little confused about the MVVM pattern which i'm combining with PRISM. In
Being confused again after reading about this anti-pattern and the many concerns about it
I am a bit confused how to best use a Regular Expression and hope
I am really confused about these three terms. My understanding is that: in the
I'm confused about when I should use a strongly typed view model vs a
This is about the Factory Pattern. I am a little confused. I saw implementations
I'm reading about the Model-View-Presenter pattern, and I'm a bit confused: can a presenter
I'm a bit confused about when using the IRepository pattern, when actually to load

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.