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 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

Just a quick question (hopefully). I want to slide one div in front of
Hopefully a very quick question. In one of my functions I want to generate
Very quick and hopefully simple question. I am trying to select a hidden input
Hopefully just a quick one. In XCode, trying to import a file called cocos2d.h
hopefully this should be a quick and simple one, using PHP I'm trying to
Quick question hopefully someone can help out here. I'm trying to copy and paste
Quick question, hopefully I am just missing something simple. Ok I have one class
Just a (hopefully) quick question, I have the following HTML code: <tr> <td><img src=img/icons/file_pdf.png></td>
Quick (and hopefully easy) question: I need to trigger a download of a PDF
Hopefully there's a quick and dirty way to remove the Ask Question (or hide

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.