I want to use all the words in the input (using the keyup function) to format the entered names.
Examples
:
john doe => John Doe
JOHN DOE => John Doe
tommy-lee => Tommy Lee
I am currently using this code:
$("input").keyup(function() { var cp_value= ucwords($(this).val(),true) ; $(this).val(cp_value ); }); function ucwords(str,force){ str=force ? str.toLowerCase() : str; return str.replace(/(\b)([a-zA-Z])/g, function(firstLetter){ return firstLetter.toUpperCase(); }); }
But if the word contains an underlined character, it also has a capital letter: John Döe => John DöE.
What is the best solution to get what I want?
thanks
source share