Need client script

User_267
Tera Contributor

For a variable (number) - it should accept only whole number ex:12 after that it need to autopopulate as ($12.00) including decimal and dollar symbol.

If alphabets or or any other apart from whole numbers are entered then it should show error.

6 REPLIES 6

Danish Bhairag2
Tera Sage
Tera Sage

Hi @User_267 ,

 

You can try below code

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    // Check if the new value contains only numbers

    if (/^\d+$/.test(newValue)) {

        // Format the value as $xx.xx

        var formattedValue = '$' + parseFloat(newValue).toFixed(2);

        // Set the formatted value back to the field

        g_form.setValue('amount', formattedValue);

    } else {

        // Display an error message

        g_form.addErrorMessage('Please enter a valid whole number.');

        // Reset the field value to the previous value

        g_form.clearValue('amount');

    }

}

 

Thanks,

Danish

 

Even for numbers like 12 it is showing alert.