The CreatorCon Call for Content is officially open! Get started here.

Should not contain alphabets special characters in the variable and allows only limited digits

Amrutha K V
Tera Contributor

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!

5 REPLIES 5

Sonam_Tiwari
Kilo Sage

@Amrutha K V ,

 

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.

 

 

Consider indicating the response as helpful and marking it as correct if it meets your needs.

Amrutha K V
Tera Contributor
Hi Sonam,
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) {
   if (isLoading || newValue == '') {
      return;
   }
    var hold = g_form.getValue('restricted_numbers_between_6_and_9');
    if(hold <6 || hold > 9){
        g_form.addErrorMessage("Only Numbers between 6 to 9 are allowed");
        g_form.clearValue("restricted_numbers_between_6_and_9");
    }
}

Thank you!

You should specify how the 'restricted_numbers_between_6_and_9' field is defined in the dictionary. Then others here can assist.

Anand Kumar P
Giga Patron

Hi @Amrutha K V ,

I tried in my  pdi its working fine for me
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​
AnandKumarP_0-1708363281692.png

 

 

 

Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand