Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

password validation (minimum # of characters and alphanumeric only)

Posted on 2004-10-14
3
Medium Priority
?
1,372 Views
Last Modified: 2008-01-09
Can you help. I have a password input text field ... (see below)

<input name="register_password" type="password" size="15" maxlength="20" onfocus="change2Msg(3);">

I need to build some validation into it ... to ONLY access alphanumeric characters A-Z a-z 0-9 with NO spaces nor other characters AND the password MUST be between 6 and 20 characters in length.

I'm don't want a pop up message ... I'm actually hoping to restrict the input of the password's unacceptable characters DURING input using something LIKE onkeyup='this.value=this.value.replace(blah);' where the blah is the stuff I don't understand and need your help with!  ...

SO to confirm ...
if I enter / click / tab into the password input field 'register_password' and I only input 4 characters ... I'm forced to stay in the input field until I enter at least 6 and no more than 20 ... AND those characters accepted are only alphanumeric.

Does this make sense? I know it's fussy but it's for a very specific need.

Richard
0
Comment
Question by:rcbuchanan
  • 2
3 Comments
 
LVL 3

Assisted Solution

by:Kupi
Kupi earned 1200 total points
ID: 12310810
I don't think it makes much sense... but here it is ;)

<input name="register_password" type="password" size="15" maxlength="20" onkeyup="this.value = this.value.replace(/[^0-9]/g, '');" onblur="if (this.value.length < 6) this.focus();">

I suggest you to alert all these errors instead of replacing the value or focusing the field... and to use a server-side validation too!

Kupi
0
 
LVL 9

Assisted Solution

by:riyasjef
riyasjef earned 800 total points
ID: 12311376
Hi
To allow only alphanumerics, this can be modified as

<input name="register_password" type="password" size="15" maxlength="20" onkeyup="this.value = this.value.replace(/[^0-9A-Z]/gi, '');" onblur="if (this.value.length < 6) this.focus();">

Riyasjef
0
 
LVL 3

Accepted Solution

by:
Kupi earned 1200 total points
ID: 12311485
Sorry, in my code I allowed only numbers... the right regexp is /[^a-zA-Z0-9]/g or /[^0-9a-z]/gi (as Riyasjef suggested)!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question