Created
June 26, 2013 15:02
-
-
Save jomasero/5868123 to your computer and use it in GitHub Desktop.
Para capitalizar la primera letra de cada palabra de un string con una expresión regular. Este código agrega un método al prototipo String para usarlo directamente en el objeto.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| String.prototype.capitalize = function() { | |
| return this.replace( /(^|\s)([a-z])/g , function(m,p1,p2){ return p1+p2.toUpperCase(); }); | |
| }; | |
| //Ejemplo de uso | |
| var miString = "hola a todos"; | |
| alert(miString.capitalize()); |
Wow! excelente aporte. Me sirvio de mucho, graciaaaas
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tu código me ayudo bastante gracias.