Validation on Amount field for numeric values, not more than 999999 and not less than zero
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 03:38 AM
In my form there in one amount field where I have kept validation so values entered will be numeric only and it must be not more than 999999 and not less that 0. This is the client script I have added -
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var flag = true;
var amnt = g_form.getValue('u_uki_amount').replaceAll(',', '');
//var regexp = /^[\d.]+$/;
var regexp = /^-{0,1}\d*(\.\d+)?$/;
if ((g_form.getValue('u_payment_type') == "Single Request") && (g_form.getValue('u_request_type') == "Cycle to Work Cancellation / Refund")) {
var newamount = newValue.replace(/[^0-9.-]/g, '');
if (newamount > 999999) {
flag = false;
g_form.clearValue('u_uki_amount');
g_form.showFieldMsg('u_uki_amount', 'Value should not exceed 999999', 'error');
}
if (newamount <= 0) {
flag = false;
g_form.clearValue('u_uki_amount');
g_form.showFieldMsg('u_uki_amount', 'Value should not less than 0', 'error');
}
}
if (!regexp.test(amnt)) {
g_form.clearValue('u_uki_amount');
g_form.showFieldMsg('u_uki_amount', 'Only numeric value is allowed', 'error');
}
//var regex = /^-{0,1}\d*(\.\d+)?$/;
//Type appropriate comment here, and begin script below
}
But whenever any user enter only "-" then it is not showing any error and If save or update button is clicked the record is getting saved but amount field is empty. This should not happen. How can I resolve this bug?\
Thanks in advance,
Krishnakant Yadav
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 06:02 AM
Hi @krishnakant
Try this below code or you will modify code like below
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// if (isLoading || newValue === '') {
// return;
// }
var num = parseInt(newValue);
var regexp = /^[+]?\d*$/;
if (!regexp.test(newValue)) {
alert('Please enter numeric value');
g_form.clearValue('u_number');
} else if (num > 999999) {
alert("Please enter value between 0 to 999999");
g_form.clearValue('u_number');
}
Please Mark Helpful or Correct answer if it really help you.