Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Regex for password policy

Reply
Thread Tools

Regex for password policy

 
 
frank_ratzlow@hotmail.com
Guest
Posts: n/a
 
      07-18-2005
Hi folks,

how can I merge these requirements into one regex?
string shall be comprised of chars from following sequences: A-Z; a-z;
0-9
string shall at least have 8 chars
at least one upper case letter should be contained (at any position)
at least one number should be contained (at any position)

Any idea?

TIA

Frank
http://www.velocityreviews.com/forums/(E-Mail Removed)

 
Reply With Quote
 
 
 
 
shakah
Guest
Posts: n/a
 
      07-18-2005
(E-Mail Removed) wrote:
> Hi folks,
>
> how can I merge these requirements into one regex?
> string shall be comprised of chars from following sequences: A-Z; a-z;
> 0-9
> string shall at least have 8 chars
> at least one upper case letter should be contained (at any position)
> at least one number should be contained (at any position)
>
> Any idea?
>
> TIA
>
> Frank
> (E-Mail Removed)


Would multiple regex's work for you, maybe:

if( Pattern.matches("[A-Za-z0-9]{8,}", sPwd)
&& Pattern.matches(".*[A-Z].*", sPwd)
&& Pattern.matches(".*[0-9].*", sPwd)) {
// ...woo hoo!
}

 
Reply With Quote
 
 
 
 
Ferenc Hechler
Guest
Posts: n/a
 
      07-18-2005

"shakah" <(E-Mail Removed)> schrieb im Newsbeitrag
news:(E-Mail Removed) ups.com...
> (E-Mail Removed) wrote:
>> Hi folks,
>>
>> how can I merge these requirements into one regex?
>> string shall be comprised of chars from following sequences: A-Z; a-z;
>> 0-9
>> string shall at least have 8 chars
>> at least one upper case letter should be contained (at any position)
>> at least one number should be contained (at any position)
>>
>> Any idea?
>>
>> TIA
>>
>> Frank
>> (E-Mail Removed)

>
> Would multiple regex's work for you, maybe:
>
> if( Pattern.matches("[A-Za-z0-9]{8,}", sPwd)
> && Pattern.matches(".*[A-Z].*", sPwd)
> && Pattern.matches(".*[0-9].*", sPwd)) {
> // ...woo hoo!
> }
>

there is no pattern for AND, but you can use "|" = OR.
So if you want to check what is not allowed you can do the following
"(.*[^a-zA-Z0-9].*)|(.{0,7})|([^A-Z]*)|([^0-9]*)"

feri


 
Reply With Quote
 
SheikhG1900 SheikhG1900 is offline
Junior Member
Join Date: Apr 2011
Posts: 1
 
      04-22-2011
string shall at least have 8 chars
at least one upper case letter should be contained (at any position)
at least one number should be contained (at any position)

Answer
^(?=.*[A-Z])(?=.*\d)(.{8,})$

Reference
http://extremecodeworld.blogspot.com...ession_22.html
 
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
Policy map using policy map Geoffrey Sinclair Cisco 1 07-27-2009 09:31 AM
How make regex that means "contains regex#1 but NOT regex#2" ?? seberino@spawar.navy.mil Python 3 07-01-2008 03:06 PM
Password policy (password expiry after certain time) morph Cisco 0 05-20-2008 08:46 PM
Default Domain Policy vs Default Domain Controller Policy Tyler Cobb MCSE 6 10-19-2005 09:36 PM
Default Domain Policy vs. Default Domain Controller Policy Tyler Cobb MCSA 1 10-09-2005 03:42 PM



Advertisments