Hi all.
I have a form with a textbox for the full name and I whant to uppercase the fist letter in the first and last name.
I have a function for that and all works well, the problem comes when there is a hypen "-" in the name. I have the split part working but on the join side I cant get it to work.
function ucFirstAllWords( str )
{
var pieces = str.split(" "); //use this for space and "-" split (/[ \/-]/);
for ( var i = 0; i < pieces.length; i++ )
{
var j = pieces[i].charAt(0).toUpperCase();
pieces[i] = j + pieces[i].substr(1);
}
return pieces.join(" ");
}
If I use this code and slpit on both space and hypen all get join with space, I have tyed to make a function in function to capture the first hyphen but that didn't work probably doing it wrong
Does anyone have any idea how to solve it?
I'm using LC 8.0
Thanks.
//Fredrik Nordstrand, Sweden
Solved! Go to Solution.
Views
Replies
Total Likes
Hi Vjay.
I want "john doe" to be "John Doe" and "ann-lee rose bush" to be "Ann-Lee Rose Bush"
Do I make any sense?
The scrip woks fine but not with a name that contains a hypen.
If I use the split to include the hypen then "ann-lee" becomes "Ann Lee" and thats not right.
Views
Replies
Total Likes
I gave "john-smith" for this im getting result as "John-smith".It is working as i expected. Is that what u wanted?
Vjay
Views
Replies
Total Likes
Hi Vjay.
I want "john doe" to be "John Doe" and "ann-lee rose bush" to be "Ann-Lee Rose Bush"
Do I make any sense?
The scrip woks fine but not with a name that contains a hypen.
If I use the split to include the hypen then "ann-lee" becomes "Ann Lee" and thats not right.
Views
Replies
Total Likes
Put this code on the exit event of the text field:
this.rawValue = this.rawValue.replace(/\b([a-z])/g, function (_, initial) {return initial.toUpperCase();});
This was originally posted by Srini in this thread:
Views
Replies
Total Likes
Thanks Jono, works great .
Very useful oneliner
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies