I can not get my formatting of currency and time to work.
Currency is to return at least one integer to the left of the decimal and two to the right and comma:
non numeric (a, a1, a1.00) and 0 --> 0.00
1 --> 1.00
1.1 --> 1.10
9999 --> 9,999.00
I have:
$("#addCostpp").blur( function(){
$("#addCostpp").val(validateCost($(this).val()));
});
function validateCost(cost_amount){
return cost_amount.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/, '$1,$2$3')
}
Time is to return 00:00:
0 (or error e.g., a or aa) --> 00:00
1 --> 01:00
01 --> 01:00
01:0 --> 01:00 (or if the : is any non numeric e.g., 01;0 or 01L0)
0101 --> 01:01
010203 --> 01:02
$("#addTimeOpen").blur( function(){
$("#addTimeOpen").val(validateTime($(this).val()));
});
function validateTime(timeString){
var formatted = "";
if (timeString.match(/^0/)){
formatted = timeString.replace(/(\d{2})(\d{2})/, "$1:$2");
}else{
formatted = timeString.replace(/(\d{1})(\d{2})/, "0$1:$2");
}
//update
return(formatted);
}