Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
| Search | Today's Posts | Mark Forums Read
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
 
Old January 23rd, 2005, 09:17 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default 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
 
Old January 24th, 2005, 01:09 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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
 
Old January 24th, 2005, 01:41 AM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

Cheers however that doesnt seem to validate the length

Wind is your friend
Matt
 
Old January 24th, 2005, 02:32 PM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

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
 
Old January 24th, 2005, 05:57 PM
Friend of Wrox
Points: 6,664, Level: 34
Points: 6,664, Level: 34 Points: 6,664, Level: 34 Points: 6,664, Level: 34
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2004
Location: Sydney, NSW, Australia.
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default

My appologies, it does indeed. It didnt seem to yesturday, obviously me using it incorrectly - thanking you.

Wind is your friend
Matt
 
Old January 25th, 2005, 12:16 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

I am glad that my code helped :)

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
 
Old January 30th, 2007, 08:54 AM
Registered User
 
Join Date: Jan 2007
Location: bangalore, Karnataka, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?:)

 
Old February 1st, 2007, 04:29 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii prashanth.j!!

replace "/^[a-zA-z]{0,55}$/" with
"/^[a-zA-Z]{0,55}$/"

hope this will help you

Cheers :)

vinod




Similar Threads
Thread Thread Starter Forum Replies Last Post
Password Validation shivendra012 ASP.NET 2.0 Professional 1 March 14th, 2007 07:10 AM
reg exp for password swarnap Javascript How-To 2 October 25th, 2006 02:04 AM
Help for username password validation ! element Classic ASP Databases 0 December 27th, 2005 08:34 AM
Window user and password validation nemovyoh VB How-To 2 April 22nd, 2005 07:43 AM
Domain Password Validation Cr0vaX Pro VB 6 3 June 21st, 2004 02:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.