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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:49:31+00:00 2026-05-17T20:49:31+00:00

Hello I am not able to get the correct validation.I think there is some

  • 0

Hello
I am not able to get the correct validation.I think there is some error in this code so can anyone please help me solving this problem.

 public static boolean validateFee(String value) {

        boolean isvalid = true;
        try {
            int fee = 0;
            if (value != null && !value.isEmpty()) {
                fee = Integer.parseInt(value);
            }
        } catch (NumberFormatException ne) {
            // ne.printStackTrace();
            isvalid = false;
            return isvalid;

        }
        return isvalid;
    }
}

I am actaully using this code for validation of fee in which i m using a regex as [0-9]+.
This code i m using it in a common function.Actually validation call is done in the servlet as follows:

private Boolean validateFee(HttpSession session, PropertiesHandler props, String number) {
    Boolean isvalid = true;
    HashMap hashMap = new LinkedHashMap();
    number = ApplicationConstants.FEE_PATTERN;
    if (!Validation.validateFee(number)) {
        isvalid = false;
        hashMap.put("time", props.getText("error.fee.invalid.type"));
    }
    session.setAttribute("errorMessage", hashMap);
    System.out.println("Map size " + hashMap.size());
    logger.info("Exit validateTIme"); return isvalid;
} 

I think there is no error in that but i have a doubt in this function.I am facing a problem like if i give number to the fee also its taking validation.please help me out

  • 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-17T20:49:32+00:00Added an answer on May 17, 2026 at 8:49 pm

    Currently it allows value of null or “” to count as being valid – is that deliberate?

    Note that your current code can be rewritten more simply:

    public static boolean validateFee(String value) {
        try {
            if (value != null && !value.isEmpty()) {
                Integer.parseInt(value);
            }
            return true;
        } catch (NumberFormatException ne) {
            return false;
        }
    }
    

    Now if you want null/empty to count as invalid, I’d rewrite it as:

    public static boolean validateFee(String value) {
        if (value == null || value.isEmpty()) {
            return false;
        }
        try {
            Integer.parseInt(value);
            return true;
        } catch (NumberFormatException ne) {
            return false;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello not sure why Im getting this error. Basically I get it in these
Hello everyone don't know why this code works on windows but not on linux
HEllo , i can not find any way to get horizontal or/and vertical resolution
Hello I asked this question to superuser but I did not get a good
Hello friends I have tried many times but I am not successful than please
Hello! I'm not even sure if this is possible, but hopefully it is in
For some reason my shell script mode hooks do not get executed. Example in
I am not able to get document.ready event or attach button click event. What
I have three code. This is the first one in which I get the
I was able to get all three running a Hello World in a Scala

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.