Change First letter to Upper With Regex - Javascript String Operation

Javascript examples for String Operation:String Case

Description

Change First letter to Upper With 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(){/*from   w ww.j  av a 2  s  . c  o m*/
function firstUpper(str) {
    return str = str.toLowerCase().replace(/^(.)|\s(.)|-(.)/g, function(letter) {
        return letter.toUpperCase();
    });
}
var foo = firstUpper("MY-TEST");
console.log(foo);
    }

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

Related Tutorials