I need to format the address with capitalized first letters and ", "
before numbers. For example:
zur sandgrube 17 -> Zur Sandgrube, 17
I'm doing this in a way that check when the textboxes are updated. However it only changes with the first function that deletes spaces and updates capitalized characters.
I think that there is something wrong with the second function indf
$("input[type='text']").change(function(e) {
switch (e.target.name) {
case 'firstname':
case 'lastname':
case 'address2':
case 'company':
case 'city':
formatta(e);
break;
case 'address1':
formatta(e);
indf(e);
break;
case 'dni':
e.target.value = e.target.value.toUpperCase();
break;
}
});
function formatta(e) {
//this work, capitalize and delete double spaces
}
function indf(e) {
var tmp = $.trim(e.target.value);
var ct = 0;
for (x = 5; x < tmp.length; x++) {
if (ct == 0) {
if (tmp.charAt(x) == 0 || tmp.charAt(x) == 1 || tmp.charAt(x) == 2 || tmp.charAt(x) == 3 || tmp.charAt(x) == 4 || tmp.charAt(x) == 5 || tmp.charAt(x) == 6 || tmp.charAt(x) == 7 || tmp.charAt(x) == 8 || tmp.charAt(x) == 9) {
ct = 1;
tmp = tmp.substring(0, x - 1) + "," + tmp.substring(x, tmp.length);
}
}
}
e.target.value = tmp;
}