Friday, 1 April 2011

Javascript function for InitCaps

The following is the simple code for converting the given string in to the init caps using javascript
function initcaps( string ) {
/* The following  Regex Replace  will  Identify  First Character
from the Word and  makes  it to  Uppercase and remaining
text to lower case */
/* This function consider only Alphanumeric Not  any 
Special Characters.*/

string =string.replace( /(\b\w)([a-zA-Z0-9]+)/gi,
function(t,a,b) { return a.toUpperCase() + b.toLowerCase(); } );
return string;
}

No comments:

Post a Comment