Should not contain alphabets special characters in the variable and allows only limited digits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 07:52 AM
Hi Team,
I have a Single Line Text variable named 'Select numbers in between 6 to 9' . Which should not contain alphabets,special characters and it should take only digits in between 6 to 9. The same time we have to populate a message : 'Please select numbers in between 6 to 9'. Could you please help me here by using onchange catalog client script.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 08:02 AM
Can you try this?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Check if the new value is a digit between 6 and 9
if (!newValue.match(/^[6-9]$/)) {
// If not, show a message to the user
g_form.clearMessages();
g_form.showFieldMsg('restricted_numbers', 'Please select numbers in between 6 to 9', 'error');
} else {
// If it is, clear any existing messages
g_form.hideFieldMsg('restricted_numbers', true);
}
}
replace restricted_numbers with your field name.
Always a good idea to post draft script that you have tried already or that didn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 08:20 AM - edited ‎02-19-2024 08:21 AM
The above script is not working.
We tried the below script initially , that time it is taking digits in between 6 to 9 but it is taking words also.
We doesn't need alphabets for the variable :restricted_numbers_between_6_and_9.
Please find the below script:
function onChange(control, oldValue, newValue, isLoading) {
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 08:36 AM
You should specify how the 'restricted_numbers_between_6_and_9' field is defined in the dictionary. Then others here can assist.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-19-2024 09:03 AM - edited ‎02-19-2024 09:22 AM
Hi @Amrutha K V ,
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var selectNumbers = g_form.getValue('u_selected_numbers');
alert(selectNumbers);
var regex = /^[6-9]$/;
if (!regex.test(selectNumbers)) {
g_form.clearValue('u_selected_numbers');
g_form.showFieldMsg('u_selected_numbers', 'Please select numbers in between 6 to 9', 'error'); // Show error message
} else {
g_form.hideFieldMsg('u_selected_numbers');
}
}
//Type appropriate comment here, and begin script below​
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand