Regex for password policy

F

frank_ratzlow

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 address removed)
 
S

shakah

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

Ferenc Hechler

shakah said:
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 address 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top