im sure this can be expanded on, cleaned up, and adjusted, but i searched here and google, noone had it completed yet.
In a nutshell, names converted to proper case with handling for spacing (just 1 right now) and McDonald and MacDonalds of the world
Any other anomoly you guys can think of please let me know.
useage - <input type=text onblur="nameCase(this);" />
In a nutshell, names converted to proper case with handling for spacing (just 1 right now) and McDonald and MacDonalds of the world
Any other anomoly you guys can think of please let me know.
Code:
function nameCase(val){
var name = val.value.toLowerCase();
var spc = 0
if (name.indexOf(' ') > 0) {
spc = name.indexOf(' ');
var name1 = name.slice(0,1).toUpperCase() + name.slice(1,spc).toLowerCase();
var name2 = name.slice(spc + 1,spc + 2).toUpperCase();
var name3 = name.slice(spc + 2).toLowerCase();
val.value = name1 + ' ' + name2 + name3;
}
else {
var name4 = name.slice(0,2);
var name5 = name.slice(0,3);
if (name4 == 'mc' || name5 == 'mac'){
spc = name.indexOf('c') + 1;
var name1 = name.slice(0,1).toUpperCase() + name.slice(1,spc).toLowerCase();
var name2 = name.slice(spc,spc + 1).toUpperCase();
var name3 = name.slice(spc + 1).toLowerCase();
val.value = name1 + name2 + name3;
}
else {
val.value = name.slice(0,1).toUpperCase() + name.slice(1,name.length).toLowerCase();
}
};
}
useage - <input type=text onblur="nameCase(this);" />