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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:43:20+00:00 2026-06-16T01:43:20+00:00

I recently learnt this code but this code is not working as it is

  • 0

I recently learnt this code but this code is not working as it is expected to .It is for form validation

function username_validation(name){
    var valid_name = /^[a-zA-Z0-9_]{5,30}$/;
    if(!valid_name.test(name)) 
     {         
         return false; 
     } 
     else 
     { 
         return true;
     } 


}
  • 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-16T01:43:21+00:00Added an answer on June 16, 2026 at 1:43 am

    You must hook this function to an event listener.
    Like :

    <form onsubmit="username_validation(this.usernameTextfield.value);">
    

    So this function will be triggered every time that particular form is submitted.
    There’s nothing wrong with your function.

    The line :

    var valid_name = /^[a-zA-Z0-9_]{5,30}$/;
    

    creates a RegExp object.

    Then :

    valid_name.test(name)
    

    checks if the name mathces with the valid_name pattern.
    RegExp has a boolean method test(s) which returns true if the given string s matches with the RegExp pattern

    A better way to write that would be :

    function validate(name) {
        var r=/^[a-zA-Z0-9_]{5,30}$/;
        return r.test(name);
    }
    

    Hope it helps…

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

Sidebar

Related Questions

My app is ready for submission now but I have recently learnt about Licensing.
I've learned a little about alignment recently but I am not certain in which
I've recently learnt about interface blocks when adding a function to my Fortran program.
This question is to discuss how to code a spell corrector and is not
Sorry if this is a simple question, but I've only recently started learn coding
I recently learnt about the benefits of EnumMap in Java and would like to
I recently learnt Python. I liked it. I just wanted to use it for
I've recently learnt about CNS and FNS , and since they look so elegant
I've been trying to learn cakephp recently but I'm struggling to find any tutorials
I do most of my development in Java and C++ but recently had to

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.