Restrict user to enter alphanumeric, lowercase and underscore(optional) only in variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 04:56 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 05:29 AM
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');
}
}