자바에서는 isUpperCase
와 isLowerCase
를 통해서 대소문자를 구분할 수 있다. JavaScript에서는 이러한 함수가 없다. 그렇다면 어떻게 확인할 수 있는지 궁금해졌다.
function isAllLowerCase(str) {
return str === str.toLowerCase();
}
console.log(isAllLowerCase('hello')); // true
function isAllLowerCase(str) {
return str === str.toUpperCase();
}
console.log(isAllUpperCase('HELLO')); // true
function isMixedCase(str) {
return str !== str.toLowerCase() && str !== str.toUpperCase();
}
console.log(isMixedCase('Hello')); // true
function isAllLowerCase(str) {
return /^[a-z]+$/.test(str);
}
function isAllLowerCase(str) {
return /^[A-Z]+$/.test(str);
}
function isMixedCase(str) {
return /^(?=.*[a-z])(?=.*[A-Z]).+$/.test(str);
}
좋은 정보 감사합니다