Example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script src="http://xregexp.com/v/3.0.0/xregexp-all-min.js"></script><script>varregex=XRegExp('([\p{Lu}]+[\p{Ll}]+|[\p{Ll}]+[\p{Lu}]+)|[0-9]+[\p{Lu}\p{Ll}]+|[\p{Lu}\p{Ll}]+[0-9]+|([^\p{L}0-9])+');console.log("Ola1: "+regex.test("Ola1"));
console.log("olá: "+regex.test("olá"));
</script>
<title>Hey</title>
</head>
<body>
</body>
</html>
Result: (see console)
Ola1: true
olá: false
Explanation:
Step 1: Include this script ( link ) no html
<script src="http://xregexp.com/v/3.0.0/xregexp-all-min.js"></script>
Step2:Declaretheregextouse
varregex=XRegExp('([\p{Lu}]+[\p{Ll}]+|[\p{Ll}]+[\p{Lu}]+)|[0-9]+[\p{Lu}\p{Ll}]+|[\p{Lu}\p{Ll}]+[0-9]+|([^\p{L}0-9])+');
Step3:Use
varresultado=regex.test("string a testar");
If the result variable is true then the string has any of the cases. Otherwise, it does not.
Only the external script is needed because regex in javascript can not recognize non-English letters (á, Á, ç, é, í, etc.)
If you do not need to recognize these letters just use:
var regex = /(([a-z]+[A-Z]+|[A-Z]+[a-z]+)|([0-9]+[A-Za-z]+)|([a-zA-Z]+[0-9])+|([\W]))/;
var resultado = regex.test("string a testar");