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

  • Home
  • SEARCH
  • 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 5958745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:35:13+00:00 2026-05-22T18:35:13+00:00

Hopefully a quick question. I’m trying to validate a double. Making sure it’s positive

  • 0

Hopefully a quick question. I’m trying to validate a double. Making sure it’s positive to one decimal place.

Good Values: 0.1, 2.5, 100.1, 1, 54
Bad Values: -0.1, 1.123, 1.12, abc, 00012.1

So I’ve tried Regex here:

 public boolean isValidAge(String doubleNumber)
{
    DoubleValidator doubleValidator = new DoubleValidator();
    return doubleValidator.isValid(doubleNumber,"*[0-9]\\\\.[0-9]");
}

I’ve also tried: "*[0-9].[0-9]", "\\\\d+(\\\\.\\\\d{1})?", "[0-9]+(\\\\.[0-9]?)?"

Nothing seems to be working. I’ve been using org.apache.commons.validator.routines.DoubleValidator

Is there another way I can do this any reason why these regex’s aren’t working? I don’t have to use regex.

Thanks

  • 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-22T18:35:14+00:00Added an answer on May 22, 2026 at 6:35 pm

    This will match a number and only a number with either a multi-digit pre-decimal point number with no leading zero(s), or just a zero, and optionally a decimal point with one decimal digit. Includes match of the beginning/end of string, so it won’t match a number in a larger string (updated to not accept leading zeros, credit @Nicklas A):

    ^([1-9]\d*|0)(\.\d)?$
    

    Use the java.util.regex.Pattern library instead.

    http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html

    Because you’re putting the regex into a string, be sure to escape the backslashes

    "^([1-9]\\d*|0)(\\.\\d)?$"
    

    I recommend that you read up on regular expressions here, they are an important tool to have “under your belt” so to speak.

    http://www.regular-expressions.info/

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

Sidebar

Related Questions

Quick (and hopefully easy) question: I need to trigger a download of a PDF
Hopefully this is a really quick one ;) I have written a lexer /
Hopefully this still falls within StackOverflow's umbrella! I'm looking to create a quick boot
Hopefully this is a simple one, but can anyone provide some simple c# code
Hopefully this is an easy one. In my app, I have an event page
Hopefully someone has seen this before. I'm trying to copy all directory contents from
This question should hopefully be easy to answer. I created a few buttons in
I'll start with an example and hopefully it will help explain my question. Say
I am looking for I one liner hopefully, that can trim the first and
Hopefully, I can get answers for each database server. For an outline of how

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.