Solved

password validation (minimum # of characters and alphanumeric only)

Posted on 2004-10-14
3
1,338 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 300 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 200 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 300 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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

803 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