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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:04:59+00:00 2026-06-04T13:04:59+00:00

I have this HTML field: <input type=text name=userInput id=userInput> I want to make sure

  • 0

I have this HTML field:

<input type="text" name="userInput" id="userInput">

I want to make sure that the user enters either at least five characters or nothing at all.

This code, which only tests for the minimum five characters is working fine:

userInputValue = $("#userInput").val();
if (/^([A-Za-z]{5,})/.test(userInputValue) === false) {
    alert("More than five, please!");
    return false;
}

However, when I try to add a condition to skip this check if the field is blank, either like this

userInputValue = $("#userInput").val();
if (userInputValue !== "") {
    if (/^([A-Za-z]{5,})/.test(userInputValue) === false) {
        alert("Either more than five or none at all, please!");
        return false;
    }
}

or like this

userInputValue = $("#userInput").val();
if (/^([A-Za-z]{5,})/.test(userInputValue) === false && userInputValue !== "") {
    alert("Either more than five or none at all, please!");
    return false;
}

the check fails completely and anything is let through. What am I doing wrong and how do I make it work? I’m not getting any info from the debugger.

  • 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-04T13:05:00+00:00Added an answer on June 4, 2026 at 1:05 pm

    Just changed a bit, adding a ? right place.

    userInputValue = $("#userInput").val();
    if (userInputValue !== "") {
        if (/^([A-Za-z]{5,})?$/.test(userInputValue) === false) {
            alert("Either more than five or none at all, please!");
            return false;
        }
    }
    

    RegEx Explantion

    "^" +              // Assert position at the beginning of a line (at beginning of the string or after a line break character)
    "(" +              // Match the regular expression below and capture its match into backreference number 1
       "[A-Za-z]" +       // Match a single character present in the list below
                             // A character in the range between “A” and “Z”
                             // A character in the range between “a” and “z”
          "{5,}" +           // Between 5 and unlimited times, as many times as possible, giving back as needed (greedy)
    ")?" +             // Between zero and one times, as many times as possible, giving back as needed (greedy)
    "$"                // Assert position at the end of a line (at the end of the string or before a line break character)
    

    Hope this helps

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

Sidebar

Related Questions

I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>
i have this html <ul> <li><form action=# name=formName></li> <li><input type=text name=someName /></li> <li><input type=text
I have this HTML code for radios: <input type='radio' name='a_27' value='Yes' id='a_27_0' /> <input
I have this html code that i want to edit with jQuery. Here is
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have a type ahead text field, and when the user hits Enter I
I have this html page which is very simple, it contains a text box
I have an input box like the following: <input type=text value= somethingSpecial=filename.txt id=myID class=box>
I want to do some autosuggest for my text field, using this plugin AutoSuggest
I have a text input which has a default value password. When the user

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.