Let's say cad is foo:
// will return false if (cad.match(new RegExp("[A-Z]"))) { resultado="mayúsculas"; // so will go there } else { // will return true if (cad.match(new RegExp("[a-z]"))) { // so will go there resultado="minúsculas"; } else { if (cad.match(new RegExp("[a-zA-z]"))) { resultado = "minúsculas y MAYUSCULAS"; } } }
Now, let's say cad is FOO:
// will return true if (cad.match(new RegExp("[A-Z]"))) { // so will go there 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"; } } }
Finally, let's say cad is FoO:
// will return true if (cad.match(new RegExp("[A-Z]"))) { // so will go there 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"; } } }
As you can see, the nested else is never visited.
What you can do is:
if (cad.match(new RegExp("^[A-Z]+$"))) { resultado="mayúsculas"; } else if (cad.match(new RegExp("^[a-z]+$"))) { resultado="minúsculas"; } else { resultado = "minúsculas y MAYUSCULAS"; }
Explanation:
^ means from the beginning of the string,
$ means to the end of the string,
<anything>+ means at least one anything.
That said,
^[A-Z]+$ means the string should only contains uppercased chars,
^[a-z]+$ means the string should only contains lowercased chars.
So if the string isn't only composed by uppercased or lowercased chars, the string contains both of them.
mayusminusto your question, including its parameters, the expected result and the actual result.