How to count the number of uppercase letters in a string?

something like this should work:

<script type="text/javascript">
str = "ThIs Is A Test On HOW tO counT UppeR CaSE";
alert(str.replace(/[^A-Z]/g, "").length);
</script>