know if all chars are capitalized in a string using regex - Javascript String Operation

Javascript examples for String Operation:String Search

Description

know if all chars are capitalized in a string using regex

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/*  w ww  . j a v a 2  s.c  om*/
function capitalized (str) {
    var len = str.length,
        noCapitals = str.replace(/[a-z]/g,''),
        percent = (noCapitals.length/len) * 100;
    return parseFloat(percent.toFixed(2));
}
var someVar = 'AAAAA DDSSS addes',
    p = capitalized(someVar);
console.log(p);

    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials