Validation on Catalog item Variable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 02:15 AM
I need to a validation on a catalog item field, Filed type is String, validation should be that it will not allow any spaces, special characters can be included but spaces are not allowed.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 02:22 AM
Hi Micky,
You can use an onChange() client script that for the string field with below code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var regex = new RegExp("^[a-zA-Z0-9]*$");
if(!regex.test(newValue)){
alert('Avoid using Spaces & Special characters.');
g_form.setValue('yourvariablefielname','');
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 02:27 AM
Hi micky09
var pattern =/^[A-Za-z'"_](\S)*$/;
/^[a-zA-Z'"-](\S)*$/
var name = g_form.getValue('updated_first_name');
if (!pattern.test(name)){
g_form.addErrorMessage("Only Characters are allowed");
g_form.setValue('updated_first_name','');
}
If it help mark helpful or correct.
Thanks and regards
Anil

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2020 02:29 AM
Hello,
This is very useful article to solve your requirement.
Also ,
If answer is helpful please mark correct or helpful!
Thanks,
Pratiksha