 |
| Javascript General Javascript discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 23rd, 2005, 09:17 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Reg Ex help for password validation
I have an annoying little bit of code that works, however I would like to shorten it. My objective is to validate a password string to
include a mix of alphanumeric characters and a minimum of seven characters. I find Reg Exp complicated, my trial and error getting it all into "if (!re.test(myString))" part of the code has been unsuccessful.
var myString = document.logInForm.pWord.value;
if(myString.length<7)
{
alert("Your password must be at least seven characters in length.");
document.logInForm.pWord.focus();
return(false);
}
var re = /^\w*(?=\w*\d)(?=\w*[a-zA-Z])\w*$/
if (!re.test(myString))
{
alert("Your password must be alphanumeric");
document.logInForm.pWord.focus();
return(false);
}
TYIA
Wind is your friend
Matt
__________________
Wind is your friend
Matt
|
|

January 24th, 2005, 01:09 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How about this?
<html>
<head>
<script language="javascript">
var myString = "abc1231" //document.logInForm.pWord.value;
var re = /^[\w]{1,7}$/
if (!re.test(myString))
{
alert("Your password must be alphanumeric"); //change the msg to include length of password also
}
else
{
alert("Pass");
}
</script>
</head>
<body></body>
</html>
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|
|

January 24th, 2005, 01:41 AM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
Cheers however that doesnt seem to validate the length
Wind is your friend
Matt
|
|

January 24th, 2005, 02:32 PM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It does validate the length as well!
To check that .. change the variable myString to some string ...say "abc123111". You could see I have validated the length by saying {1,7} in the regular expression. It means at least it needs one character and the max it can have is 7. Hope this helps.
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|
|

January 24th, 2005, 05:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
|
|
My appologies, it does indeed. It didnt seem to yesturday, obviously me using it incorrectly - thanking you.
Wind is your friend
Matt
|
|

January 25th, 2005, 12:16 AM
|
|
Friend of Wrox
|
|
Join Date: Dec 2004
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I am glad that my code helped :)
Best Regards
Vadivel
MVP ASP/ASP.NET
http://vadivel.thinkingms.com
|
|

January 30th, 2007, 08:54 AM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi ,
I want a regular expression in java script that should return true if it contains
[a-z] and [A-Z] and [0-9].I tried "/^[a-zA-
z]{0,55}$/" but it is taking or condition between [a-z] , [A-z]
i want and condition to be implemented in between [a-z] , [A-z]
Can any one help me on this?:)
|
|

February 1st, 2007, 04:29 AM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hii prashanth.j!!
replace "/^[a-zA-z]{0,55}$/" with
"/^[a-zA-Z]{0,55}$/"
hope this will help you
Cheers :)
vinod
|
|
 |