473,396 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

password validation with reg exp

I need to validate a password to only allow A-Z, a-z and 0-9. I
thought this would work:

function Validate()
{
var passphrase = document.all.challenge.value;

var re = /[a-zA-Z0-9]/;
if (!re.test(passphrase))
{
alert("Please enter a valid password!");
return false;
}
else
{
return true;
}
}

however if the following is entered 045# - this is accepted a being
valid. What am i doing wrong?

thanks,

Obitoo
Jul 20 '05 #1
1 4859
ob****@ziplip.com (Obi-Too) writes:
I need to validate a password to only allow A-Z, a-z and 0-9. I
thought this would work: .... var re = /[a-zA-Z0-9]/;


This RE matches any string that contain at least one digit or letter,
not just strings that contain only those.

Try
/^[a-z0-9]+$/i
This matches from the beginning of the string (^) to the end ($) and
between there are one or more letters or digits. The "i" means "ignore
case", so we don't have to write both a-z and A-Z.

Another test is
/[^a-z0-9]/i
this succeedes if the string contains any non-digit/letter. You can the
use
if (re.test(...)) { // password failed

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lim Eng Teik | last post by:
I was asked by a client to make changes for their Outlook Web Access page where I need to validate Expiry Date of the Password and also the Password Length for the NT Account Policy. Initially I...
2
by: Christian Carlsen | last post by:
Hello, I need to validate a password: In order for the password to be accepted the following requirements must be met: At least one uppercase character (position in password is irrelevant) At...
1
by: brijesh | last post by:
i am relatively new to javascript i am trying for a password validation code but iam not able to stop the page from loading the page when the password is wrong. the code is as below...
7
by: Mike | last post by:
I've been trying for the past week to put a simple code together. I have done a LOT of searching, found scripts showing the functions I would like to use, however when I mix them it all goes wrong,...
9
by: Stirling | last post by:
Hi all, hope someone can help me, I am looking to do a password validation check using client side validation. Minimum requirement is that it must contain at least one number and one letter. ...
3
by: Morgan Roderick | last post by:
Hi How do I control the password complexity for users registering themselves in a webapp using Membership? From http://beta.asp.net/QUICKSTART/aspnet/doc/security/membership.aspx "Note that...
0
by: Steven | last post by:
Currently, I want to create a setup project which needs the user to input a specify password or validation code before installation. If the input password/validation code is not correct, the...
15
by: Eugene Anthony | last post by:
Is this method of validation for password and username considered to be secured. In my previous post I was given a solution that uses command object and the values are parsed by parameters. But the...
10
by: canam | last post by:
Hi: I hope someone can help me. Is there a way to add a password to a particular field in the event that the validation rule must be over written? I've created an input form in a...
1
by: shwethatj | last post by:
My problem is lik this , I am trying to create a registration form using javascript for a HR website , but i dont know how to provide password validation i.e the password and confirmation password...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.