Javascript examples for String Operation:String Case
Change First letter to Upper With Regex
<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>