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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:39:44+00:00 2026-06-18T02:39:44+00:00

I have a hangman game created in java. I want to create a simple

  • 0

I have a hangman game created in java. I want to create a simple function that will check if the word input has white space and/or special characters.

I’ve found the functions String.replaceAll(), but I haven’t been able to dig up a premade function that returns a boolean value for if there are special charactors and/or white space.

Is there a function out there already? Or at least a simpler way of specifying no white space or special characters other than doing the following?

public  void checkWord()
    {
        boolean flag = false;
        for(int i=0;i<wordArray.length;i++)
        {
            if(wordArray[i] == '1' || wordArray[i] == '2' || wordArray[i] == '3' || wordArray[i] == '4' || wordArray[i] == '5' || wordArray[i] == '6' || wordArray[i] == '7' || wordArray[i] == '8' || wordArray[i] == '9'  )
            {
                flag = true;
            }
        }
        if(flag == true)
        {
            System.out.println("Invalid characters used in the word");
            System.exit(0);
        }
    }

The function is getting dense, and I’ve only covered digits. Thoughts?

  • 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-18T02:39:45+00:00Added an answer on June 18, 2026 at 2:39 am

    You can use a simple regular expression:

    public boolean isValidWord(String w) {
        return w.matches("[A-Za-z]*");
    }
    

    Explanation of the regex:

    [A-Za-z] - capital or lowercase letter
    *        - zero or more
    

    More info on regexes: 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

I'm doing a hangman game, and just started to created the random word that
**Hello, I have to create a hangman game in java. I cant use arrays.
For a class project, we have to create a hangman game in Java (we're
I have a very specific question regarding my Hangman program. You will probably want
I have created a hangman based on a jQuery code that I found online.
Have a painfully simple blog Post creator, and I'm trying to check if the
I'm trying to write a little CLI Hangman game, just to create something in
So, I am creaing a Hangman game, with a word editor to put your
I'm programming a traditional hangman game in Java. What I'm currently stuck on is
I am making a hangman game and I want to be able to reset

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.