Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Restrict user to enter alphanumeric, lowercase and underscore(optional) only in variable

Atheher Fathima
Mega Guru

Hi All,

 

My Requirement is to make a variable restriction where we allow users to enter only alphanumeric , lower case and underscore (optional). we need to restrict all other special characters spaces and line breaks.

I have created a catalog client script on change as below

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

var regex = new RegExp("^[a-z0-9]*_");


if(!regex.test(newValue)){


alert('Please note that application ID should not contain special characters or spaces.Please user lower case only');


g_form.setValue('u_application_id_tag','');

}
}

 

However I see that it is mandatory to have "_" or a number using this script. I would like to have the ability to fill the field with alphanumeric lower case only that may or may not contain numbers or underscore. How do i achieve this?

 

any assistance on this is greatly appreciated.

1 REPLY 1

Community Alums
Not applicable

Hi @Atheher Fathima ,

so only alphabets a to z lowercase and A to Z uppercase and only 1 special character i.e. underscore is allowed.

use this script in client side

I believe this you want in onchange client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}

if(!/^[a-zA-Z_]+$/i.test(newValue)){
alert('Please enter only upper/lower case alphanumeric & underscore character');

g_form.clearValue('fieldName');

}

}