Do you [!]HAVE[/!] to check for length with the other criteria all in the same regexp? You can do this, but you're looking at a VERY long regexp because you will have to check for all examples up to 8 characters. For example:
[small]
0 characters, 1 upper case character, 1 number, at least 6 more characters
or
0 characters, 1 number, 1 upper case character, at least 6 more characters
or
1 character, 1 upper case character, 1 number, at least 5 more characters
or
1 character, 1 number, 1 upper case character, at least 5 more characters
or
0 characters, 1 upper case character, 1 character, 1 number, at least 5 more characters
etc.[/small]
it would be [!]MUCH[/!] easier to make it a 2 step validation process (not to mention you would be able to customize your error messages to the specific problem):
Code:
<script type="text/javascript">
function validateText(str) {
if (str.length < 8) {
alert("String must be at least 8 characters");
return false;
}
var a = str.match(/(.*[A-Z].*\d.*|.*\d.*[A-Z].*)/);
if (a == null) {
alert("String must contain at least 1 numeric character, and one upper case letter");
return false;
}
return a;
//a will contain an array of information regarding the matches
}
</script>
<input type="text" id="blah" />
<input type="button" value="validate" onclick="validateText(document.getElementById('blah').value)" />
-kaht
[small]How spicy would you like your chang sauce? Oh man... I have no idea what's goin' on right now...[/small]
![[banghead] [banghead] [banghead]](/data/assets/smilies/banghead.gif)