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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:52:34+00:00 2026-06-08T20:52:34+00:00

I have problem with two of my methods for password validation. The method hasDigitsAndLetters

  • 0

I have problem with two of my methods for password validation.
The method hasDigitsAndLetters is supposed to check whether all the characters of the String are digits and letters and the second method hasTwoDigits is supposed to check whether there are at least two digits in the pass, but the problem is that for expected result true they are ruturning false. If someone can help. here is the code.

//check if the whole string consists of digits and letters
    public static boolean hasDigitsAndLetters(String pass)
    {
        for(int i=0; i<pass.length(); i++)
        {
            if(!Character.isLetterOrDigit((i)))
            {
                return false;
            }

        }
        return true;
    }



    // check whether the password has at least 2 digits
    public static boolean hasTwoDigits(String pass)
    {
        int counter = 0;
        for(int i=0; i<pass.length(); i++)
        {
            if(Character.isDigit(i))
            {
                counter ++;
            }

        }
        System.out.println("Number of digits: " + counter);
        if(counter >= 2)
        {
            return true;
        }
        return false;
    }
  • 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-08T20:52:35+00:00Added an answer on June 8, 2026 at 8:52 pm

    You need to pass character at position i for that String.

    Character.isLetterOrDigit((pass.charAt(i)))
    

    same for digit also

    Character.isDigit((pass.charAt(i)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user model with two [NotMapped] string properties Password and ConfirmPassword. These
I'm using this datamapper http://datamapper.wanwizard.eu problem is datamapper have validation methods similar with codeigniter
I Have two problem in this Case : I want to pass a JSON
I have a problem with two Textviews on the same height in a RelativeLayout
I have had this problem w/ two seperate WYSWYG editors in my rails application
I have an strange problem using two borders. I use them to display video
Hello I have problem to put together animations of two separate objects to second
Problem: I have two array where one produce a category and the second produce
I have a design problem: I have two threads, a heartbeat/control thread and a
I have a problem with IE causing two errors: 1. Object doesn't support this

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.