Skip to content Skip to sidebar Skip to footer

Javascript/jquery Uppercase First Letter Of Variable With Accents

I have a form with some text inputs to insert First Name, Last Name of a person, but I want to change the first letter of each word to a Uppercase and I found this solution: // Th

Solution 1:

\b is a non word boundary (i.e \b would make a boundary for any any character which doesn't belong to any 1 of [0-9a-zA-Z_])

So those accented word become the boundary for your word..

Instead use this regex

/(^|\s)[a-z\u00E0-\u00FC]/g

Solution 2:

[a-z] doesn't match é. You'll have to be a bit more lenient:

"gonzález foo bar, baz él".replace(/(^|\s)\S/g, function(match) {
    return match.toUpperCase();
});

And the output:

"González Foo Bar, Baz Él"

Post a Comment for "Javascript/jquery Uppercase First Letter Of Variable With Accents"