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
new RegExp("[A-Z]")
matches when any character in cadena
is an upper-case letter.
To match when all characters are upper-case, use
new RegExp("^[A-Z]+$")
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]
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With