Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Java
Expertise: Beginner
Oct 27, 2000

Convert an Input String Into a Proper String


If you want to convert the input string into a proper string using javascript, this is a simple function that will perform the task:
 
String.prototype.ProperCase = function() {

      return this.substr(0,1)
                  .toUpperCase() +  
                  this.substr(1, this.length)
                  .toLowerCase()
                  .replace(/((\s|')[a-z])/g, function($0,$1,$2) {
                        return $1.toUpperCase();  
                  });
}

This function can convert conpound names correctly (eg., "o'brian" will return "O'Brian").
Jose Marcos
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date