3 回答
TA贡献1906条经验 获得超10个赞
如果字符或整个字符串为数字,则josh和maleki的答案在大写和小写形式上都将返回true。使结果为假结果。使用乔什的例子
var character = '5';
if (character == character.toUpperCase()) {
alert ('upper case true');
}
if (character == character.toLowerCase()){
alert ('lower case true');
}
另一种方法是先测试它是否为数字,否则测试它是否为大写或小写示例
var strings = 'this iS a TeSt 523 Now!';
var i=0;
var character='';
while (i <= strings.length){
character = strings.charAt(i);
if (!isNaN(character * 1)){
alert('character is numeric');
}else{
if (character == character.toUpperCase()) {
alert ('upper case true');
}
if (character == character.toLowerCase()){
alert ('lower case true');
}
}
i++;
}
TA贡献1796条经验 获得超7个赞
if (character == character.toLowerCase())
{
// The character is lowercase
}
else
{
// The character is uppercase
}
添加回答
举报