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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:56:35+00:00 2026-05-23T01:56:35+00:00

Been playing around with JavaScript, and what Im trying to do is only allow

  • 0

Been playing around with JavaScript, and what Im trying to do is only allow certain characters in the pass word field – a-z, A-Z and 0-9.

<form action="http://www.cknuckles.com/cgi/echo.cgi" method="get" name="logOn">
  User Name:<br />
  <input type="text" name="userName" size="25" /><br />
  Password:<br />
  <input type="password" name="pw" size="25" /><br />
  <input type="submit" value="Log In" onClick="validate()"/> 
</form>

Above is my HTML, and Below is my JavaScript I tried to use to validate it – but it doesnt work – any clues.

<script language="javascript">
   document.logOn.onsubmit=validate;

   function validate(){

var name=document.logOn.pw.value;
    if(!name = "[a-zA-Z0-9]"){              
alert("Your Password Cant Have Any Funky Things In It - Play It Straight!");
    return false;
}               

    return true;
}
</script>

But This isnt working. I can still put chars in like “*” and “[” and “{” etc.

Any 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-05-23T01:56:36+00:00Added an answer on May 23, 2026 at 1:56 am

    You need to make your condition test a regexp, not a string:

    if(!/^[a-zA-Z0-9]+$/.test(name)){ ...
    

    meaning:

    • ^ — start of line
    • [a-zA-Z0-9]+ — one or more characters/numbers
    • $ — end of line

    or you could search for the inverse of that, which is “any non-accepted character”:

    if(/[^a-zA-Z0-9]/.test(name)){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been playing around with prototypal inheritance after reading http://javascript.crockford.com/prototypal.html and having a bit
I've been playing around with trying to create a droppable accordion for a little
I have been playing around JavaScript for a year or so, one thing I
I've been playing around trying to create a transparent window that will overlay another
I have been playing around with the merge command in R and am trying
I've been playing around with creating an application using the S#arp Architecture . One
I've been playing around with Qt for a few hours now. I found that
I have been playing around with the postgresql.conf file for a couple days now.
I've been playing around with ASP.NET MVC with a site containing a Master Page.
I have been playing around with the EF to see what it can handle.

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.