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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:13:12+00:00 2026-05-29T06:13:12+00:00

I have some JQuery form validation where im checking the length of the username

  • 0

I have some JQuery form validation where im checking the length of the username is not long for the database but it seems to be returning true eveytime.

Am I missing something?

HTML

<form name="contact" method"post" action="">
<fieldset>

<label for="username" id="username_label" class="form_label">Username</label>
<input type="text" name="username" id="username" size="30" value="" class="text-input" />
<label class="error" for="username" id="username_error">This field is required.        </label>
<label class="error" for="username" id="username_length">Your Username should be less than 30 characters.</label>
<input type="submit" name="submit" class="button" id="submit_btn" value="Send" />
</fieldset>
</form>

JavaScript

$(function() {
$('.error').hide();
$(".button").click(function() {
  // validate and process form here

$('.error').hide();
  var username_length = $("input#username").val().length;
    if (username_length < 30) {
    $("label#username_length").show();
    $("input#username").focus();
    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-05-29T06:13:12+00:00Added an answer on May 29, 2026 at 6:13 am

    I have some JQuery form validation where im checking the length of the username is not long for the database but it seems to be returning true eveytime.

    You are checking if unsername is shorter then 30, not longer!

    if (username_length < 30) {// !!!
    

    note:

    • There is no need to add element type for id selector id is unique, anything added to it, will increase the overhead of the selector

    $("input#username") => $('#username')

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

Sidebar

Related Questions

I have a form with jquery validation. I have some custom rules, but they
I have to fix some form validation but there's no jQuery included in the
I have been working on some form validation in jQuery. Everything was going nicely
I have some client-side JavaScript validation on a form. It works great. But I
I have some problems sending an id though jquery. I have a form select
I have some jquery code that is doing an ajax lookup and returning comma
I use jQuery form validation plugin to validate some form fields. As for now
I'm using the jQuery Validation plugin on my forms. I have some groups of
I have a form using jquery validation plugin. My submit button has an ajax
I'm doing some jQuery form validation and I came up with an issue. I

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.