I have this code:
var cadena = prompt("Cadena:");
document.write(mayusminus(cadena));
function mayusminus(cad){
var resultado = "Desconocido";
if(cad.match(new RegExp("[A-Z]"))){
resultado="mayúsculas";
}else{
if(cad.match(new RegExp("[a-z]"))){
resultado="minúsculas";
}else{
if(cad.match(new RegExp("[a-zA-z]"))){
resultado = "minúsculas y MAYUSCULAS";
}
}
}
return resultado;
}
I always have mayusculas or minusculas, never minusculas y MAYUSCULAS (MIXED), I am learning regexp and dont know my error yet :S
matches when any character in
cadenais an upper-case letter.To match when all characters are upper-case, use
The
^forces it to start at the start, the$forces it to end at the end and the+ensures that between the end there are one or more of[A-Z].