Click to See Complete Forum and Search --> : Regular Expression for Password


jrlaughlin
07-15-2003, 09:45 AM
Hello all,

Hoping there is a regular expression guru out there...I don't do it enough to be good at it.

I need a regular expression that will match the following conditions.

<li>at least 8 characters long
<li>not longer than 15 characters
<li>must contain at least one number
<li>can contain only numeric and alpha (upper and/or lower) characters
<li>must start with an upper or lowercase alpha character

Here is what I have been working with.
^[a-zA-Z]+[a-zA-Z0-9]{7,14}$

Doesn't work quite right...not sure what I'm doing wrong.

Any help will be appreciated.

jrlaughlin
07-15-2003, 10:23 AM
I think I have made some progress:

^([a-zA-Z]\w{7,14})$

this matches anything between 8-15 characters that begins with an alpha character....but does not enforce the numeric character requirement.

No takers?

Jeff Mott
07-15-2003, 11:44 AM
\wNote that this also includes the underscore, just in case you weren't aware.

Requiring that at least one digit be present does not fit well with the rest and would be easiest in a separate expression./^[a-z]\w{7,14}$/i && /\d/

jessevitrone
07-15-2003, 12:28 PM
This is the best I could come up with. I split it into 2 checks.

This checks the "starts with an alpha, then has more alpha's and numbers, with at least 1 number":
var matchedChars = /^[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*$/.test(foo);

This checks the length:
var matchedLength = /^.{8,15}$/.test(foo);

Hope that helps.

Jes