Possible Duplicate:
Convert string to Pascal Case (aka UpperCamelCase) in Javascript
I'm doing some quite basic stuff here so bear with me..
I'm using an XHTML text input to get a users name. I'm then showing an alert message via javascript. I've made it so that the first letters of the users names are capitalised via text-transform: capitalize;
but javascript reads the original entry and doesn't take account of this.
What is the simplest solution I can use so that the alert is also capitalised in the same way? Preferably the less code the better so I can understand it easily :)
Thanks
var titleCase = 'make me look GOOD'.toLowerCase().replace(/(?:^|\s)[a-z]/g, function(match) {
return match.toUpperCase();
});
jsFiddle.
Output
Make Me Look Good
精彩评论