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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:46:31+00:00 2026-05-10T13:46:31+00:00

So I am writing a registration form and I need the display name to

  • 0

So I am writing a registration form and I need the display name to be only numbers, letters and underscores.

Have a look at my code and tell me what I’m doing wrong.

<form method='post' action='/' onsubmit='return check_form()'>     <input type='text' id='display-name' name='display-name' maxlength='255' />     <input type='submit' /> </form> <script type='text/javascript'> <!--     var name_regex = /^([a-zA-Z0-9_])+/      function check_form()     {         if (!name_regex.test(document.forms[0].elements[0].value))         {             document.forms[0].elements[0].focus()             alert('Your display name may only contain letters, numbers and underscores')             return false         }     } --> </script> 

It’s obviously been trimmed down to not include anything not related to the problem but even this snippet doesn’t work.

  • 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. 2026-05-10T13:46:32+00:00Added an answer on May 10, 2026 at 1:46 pm

    Your regex

    /^([a-zA-Z0-9_])+/ 

    Looks for

    1. Start of string(check), followed by
    2. 1 or more letters, numbers, or underscore (check)

    And then whatever comes after it doesn’t matter. This regex will match anything at all so long as it begins with a letter, number, or underscore

    If you put a $ at the end, then it will work – $ matches ‘end of string’, so the only way it can match is if there are only numbers, letters, and underscores between the start and end of the string.

    /^([a-zA-Z0-9_])+$/ 

    Secondly, I’d suggest using document.getElementById('display-name').value instead of document.forms as it won’t break if you rearrange the HTML, and is more ‘the commonly accepted standard of what to do’

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

Sidebar

Related Questions

I'm writing a simple registration form to add users to a database. The code
i follow the tutorial from youtube writing a code of login & registration but
I am writing a user registration form. After the user registers with a username
I'm writing a simple script that submits the registration form to my site via
I have a registration form that is rendered by the following urlconf -- url(r'^$',
I have a registration form which validates the users email with JS and PHP
I was writing an application that required login and registration, so I look up
I use a registration form that asks users to enter their full name into
I'm now writing a registration screen before my tabBar shows up. My idea is
I'm writing an Account module which should take care of everything about accounts: registration,

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.