Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > More questions about search function on regular expressions

Reply
Thread Tools

More questions about search function on regular expressions

 
 
.Net Sports
Guest
Posts: n/a
 
      05-08-2007
I posed this problem last month here, but need more of a
clarification, as I still cannot correctly flag a bad password. I need
users to submit a passowrd that has at least one numeric character,
along with any amount of string-alpha characters (8 numeric characters
and 1 string character is fine, for example), but having trouble with
the correct regex, as the below still doesnt raise the error alert
when all strings with no numbers are entered:

<script language="JavaScript" type="text/javascript">
function validatePassword(password) {
var error = "";
var illegalChars = /[\W_]/; // allow only letters and numbers

if (password.value == "") {
password.style.background = 'Yellow';
error = "You didn't enter a password.\n";
} else if ((password.value.length < 7) || (password.value.length >
15)) {
error = "The password is the wrong length. \n";
password.style.background = 'Yellow';
} else if (illegalChars.test(password.value)) {
error = "The password contains illegal characters.\n";
password.style.background = 'Yellow';
} else if (!((password.value.search(/[A-Z]+[a-z]+[0-9]/)))){ // &&
(password.value.search(/(0-9)+/)))) {
error = "The password must contain at least one numeral.\n";
password.style.background = 'Yellow';
} else {
password.style.background = 'White';
}
return error;
}

</script>

Thanks in advance
netsports

 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-08-2007
..Net Sports wrote on 08 mei 2007 in comp.lang.javascript:

> I posed this problem last month here, but need more of a
> clarification, as I still cannot correctly flag a bad password. I need
> users to submit a passowrd that has at least one numeric character,
> along with any amount of string-alpha characters (8 numeric characters
> and 1 string character is fine, for example), but having trouble with
> the correct regex, as the below still doesnt raise the error alert
> when all strings with no numbers are entered:
>




> <script type="text/javascript">


do not use: language="JavaScript"

> function validatePassword(password) {


make sure password is the right object by using the "this" keyword

> password.style.background = 'Yellow';


yellow , no uppercase


> if (!((password.value.search(/[A-Z]+[a-z]+[0-9]/)))){ // &&
> (password.value.search(/(0-9)+/)))) {


I don't understand these last two lines with // and two { {

> password.style.background = 'White';


white

================

Try this, much simpler code:

<script type="text/javascript">

function validatePassword(password) {
password.style.backgroundColor = 'yellow';
if (password.value == '')
return 'You didn't enter a password.\n';
if ((password.value.length < 7) ||
(password.value.length >15))
return 'The password is of the wrong length.\n';
if (/[\W_]/.test(password.value))
return 'The password contains illegal characters.\n';
if (/\d/.test(password.value))
return 'The password must contain at least one numeral.\n';
password.style.backgroundColor = 'white';
return "";
}

</script>


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
 
Evertjan.
Guest
Posts: n/a
 
      05-08-2007
Evertjan. wrote on 09 mei 2007 in comp.lang.javascript:

> Try this, much simpler code:
>
> <script type="text/javascript">
>
> function validatePassword(password) {
> password.style.backgroundColor = 'yellow';
> if (password.value == '')
> return 'You didn't enter a password.\n';
> if ((password.value.length < 7) ||
> (password.value.length >15))
> return 'The password is of the wrong length.\n';
> if (/[\W_]/.test(password.value))
> return 'The password contains illegal characters.\n';
> if (/\d/.test(password.value))


if (!/\d/.test(password.value))

> return 'The password must contain at least one numeral.\n';
> password.style.backgroundColor = 'white';
> return "";
>}
>
> </script>
>




--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
re.search much slower then grep on some regular expressions Henning_Thornblad Python 46 07-10-2008 05:15 PM
excluding search string in regular expressions Franz Steinhaeusler Python 9 10-22-2004 08:54 AM
regular expressions and search() - vertical bar problem Ward Cleaver Javascript 6 09-30-2004 03:36 AM
Problem with global text search using Regular Expressions Jayal Perl Misc 9 09-22-2004 06:58 AM
Add custom regular expressions to the validation list of available expressions Jay Douglas ASP .Net 0 08-15-2003 10:19 PM



Advertisments