Javascript String capitalize(lower)

Description

Javascript String capitalize(lower)


'use strict';//ww  w  . j ava  2  s.  co  m

String.prototype.capitalize = function(lower) {
    return (lower ? this.toLowerCase() : this).replace(
        /(?:^|\s)\S/g,
        function(a) { return a.toUpperCase(); });
};

Javascript String capitalize(lower)

String.prototype.capitalize = function(lower) {
    return (lower ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};

Javascript String capitalize(lower)

/**//from   w ww.j av  a2s  .c om
 * From: http://stackoverflow.com/questions/2332811/capitalize-words-in-string
 */
String.prototype.capitalize = function(lower) {
  return (lower ? this.toLowerCase() : this).replace(/(?:^|\s)\S/g, function(
      a) {
    return a.toUpperCase();
  });
};



PreviousNext

Related