1

I have a text box in my web form. In jQuery I have to verify that the entered text should have at least one lowercase and one uppercase letter. How does the pattern look?

2
  • What have you tried? Commented Mar 16, 2012 at 14:10
  • 1
    That searches for a string that starts with 5 characters that may be any of upper or lower case letters. It doesn't require anything beyond that. See answers below. Commented Mar 16, 2012 at 14:30

3 Answers 3

3

Assuming ERE:

/([A-Z].*[a-z]|[a-z].*[A-Z])/ 

or if you're a purist:

/([[:upper:]].*[[:lower:]]|[[:lower:]].*[[:upper:]])/ 
Sign up to request clarification or add additional context in comments.

8 Comments

How good is the POSIX notation compatible to the browsers, do you know?
@yunzen - JavaScript supports Perl-compatible regular expressions. You can compare flavours and their capabilities if you like. If you're asking whether PCRE supports Character Classes, the answer is yes, it does.
@yunzen Javascript’s native regexes are pretty lame, and not very Perl-compatible at all. The XRegexp plug-in goes a long ways toward fixing that.
@ghoti but my flavor of Chrome RegEx does not support the :lower: and :upper: POSIX Character Classes. It supports :Alpha: and :alpha:
@tchrist Thanks for the link. I'll savor this for me.
|
0
/[a-z].*[A-Z]|[A-Z].*[a-z]/ 

Test here: http://www.regular-expressions.info/javascriptexample.html (without the /)

Comments

0
 //TODO check Number var checkNumber = false var matches = currentPassword.match(/\d+/g) ||newPassword.match(/\d+/g) || confirmPassword.match(/\d+/g) ; if (matches != null) { checkNumber = true; } //TODO check Letter var checkLetter = false var matchesLetter = currentPassword.match("[a-z\A-Z]") || newPassword.match("[a-z\A-Z]") || confirmPassword.match("[a-z\A-Z]") ; if (matchesLetter != null) { checkLetter = true; } //TODO check upper and lower Letter var checkUpperLowerLtr = false var matchesUpperLowerLtr = currentPassword.match("[a-z].*[A-Z]|[A-Z].*[a-z]") || newPassword.match("[a-z].*[A-Z]|[A-Z].*[a-z]") || confirmPassword.match("[a-z].*[A-Z]|[A-Z].*[a-z]"); if (matchesUpperLowerLtr != null) { checkUpperLowerLtr = true; } //TODO Special var checkSpecial = false var matchesSpecial = currentPassword.match("/?[#?!@$%^&*-]") || newPassword.match("/?[#?!@$%^&*-]") || confirmPassword.match("/?[#?!@$%^&*-]") ; if (matchesSpecial != null) { checkSpecial = true; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.