Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
97
rated 0 times [  98] [ 1]  / answers: 1 / hits: 107944  / 14 Years ago, thu, may 13, 2010, 12:00:00

Consider a JavaScript method that needs to check whether a given string is in all uppercase letters. The input strings are people's names.



The current algorithm is to check for any lowercase letters.



var check1 = Jack Spratt;    
var check2 = BARBARA FOO-BAR;
var check3 = JASON D'WIDGET;

var isUpper1 = HasLowercaseCharacters(check1);
var isUpper2 = HasLowercaseCharacters(check2);
var isUpper3 = HasLowercaseCharacters(check3);

function HasLowercaseCharacters(string input)
{
//pattern for finding whether any lowercase alpha characters exist
var allLowercase;

return allLowercase.test(input);
}


Is a regex the best way to go here?



What pattern would you use to determine whether a string has any lower case alpha characters?


More From » regex

 Answers
1

also:



function hasLowerCase(str) {
return (/[a-z]/.test(str));
}

[#96790] Tuesday, May 11, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
herman

Total Points: 110
Total Questions: 90
Total Answers: 108

Location: Bosnia and Herzegovina
Member since Thu, Jun 24, 2021
3 Years ago
;