Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Regex for password policy (http://www.velocityreviews.com/forums/t144927-regex-for-password-policy.html)

frank_ratzlow@hotmail.com 07-18-2005 03:56 PM

Regex for password policy
 
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
frank_ratzlow@nojunk.hotmail.com


shakah 07-18-2005 05:19 PM

Re: Regex for password policy
 
frank_ratzlow@hotmail.com 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
> frank_ratzlow@nojunk.hotmail.com


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!
}


Ferenc Hechler 07-18-2005 06:31 PM

Re: Regex for password policy
 

"shakah" <shakahshakah@gmail.com> schrieb im Newsbeitrag
news:1121707158.533183.68390@f14g2000cwb.googlegro ups.com...
> frank_ratzlow@hotmail.com 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
>> frank_ratzlow@nojunk.hotmail.com

>
> 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



SheikhG1900 04-22-2011 12:17 PM

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


All times are GMT. The time now is 05:05 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.