I would like to autocorrect a field for initials, but my knowledge is limited, so after an hour of trial and error, all I have is a small script that just uppercases the input. What I would like is this:
-
a becomes A. (uppercase and ends with a dot)
-
AbC becomes A.B.C.(uppercase and seperated by a dot)
-
A1BC_* becomes A.B.C. (no other characters allowed, uppercase and seperated by a dot)
What I have is this:
$(".hoofdletters").keyup(function(e)
{
$(".hoofdletters").val(($(".hoofdletters").val()).toUpperCase());
});
Update
I don’t want to waste anyones time and open a new topic, so i try it here. I tried something myself as well to automatically capitalize every word in a sentence. Everything is working, but for some reason the space get’s deleted. It has something to do with + '' If i delete that nothing works anymore, if i add a space i get a space after every letter and if i leave it this way, then spaces are not allowed.
Anyone any suggestion?
$('.cap').bind('textchange', function (event, previousText) {
var val = this.value;
var newVal = '';
val = val.split(' ');
for(var c=0; c < val.length; c++) {
newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ''; // It has something to do with this line
}
this.value = newVal;
});
Fiddle