Skip to content

Instantly share code, notes, and snippets.

@hmbr
Created October 24, 2011 17:09
Show Gist options
  • Save hmbr/1309532 to your computer and use it in GitHub Desktop.
Save hmbr/1309532 to your computer and use it in GitHub Desktop.
capitalizeInput
(function($) {
$.fn.capitalizeInput = function(){
var content = $(this).val().toLowerCase();
var pos = 0;
var space = -1;
var min_length = 2;
var values = content.split("");
while (-1< pos && pos <content.length ){
space= content.indexOf(" ",pos);
if (space<0){
if ((content.length - pos)>= min_length && values[pos+1].match(/\w/)){
values[pos] = values[pos].toUpperCase();
}
pos = space;
}else{
if ((space - pos)>= min_length && values[pos+1].match(/\w/) ){
values[pos] = values[pos].toUpperCase();
}
pos = space+1;
}
}
$(this).val(values.join(""));
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment