naeemqaswar
2/16/2017 - 10:24 AM

Validates form input price values to floating or int number

Validates form input price values to floating or int number

function get_validated_input_number(val, is_float = 0) {

    if(val){

        val = String(val).trim();
        val = val.replace('€','');

        if(is_float){
            val = parseFloat(val);
        } else {
            val = parseInt(val);
        }

        if(isNaN(val)){
            val = 0;
        } else {
            if(is_float){
                val = roundToTwo(val);
            }
        }

    } else {
        val = 0;
    }

    return val;
}