- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 05:56 AM
Hi,
I have the field 'name' of type string in my catalog item. I need to write on change client script on this field.
The user can type only these combination of characters:
1) small english letters
2) numbers
3) he can use only the special symbol '-' (e.g Alon-)
4) not more than 64 characters in total
* If the users does not meet these condition, he needs to see an error and he cant submit the catalog item until he fix the value that was entered.
Can anyone plesae help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 11:05 AM
Please check this solution if this is worked for you!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.clearMessages();
var pattern = /^[a-z0-9-]*$/;
if (newValue.length > 64 || !(pattern.test(newValue))) {
g_form.addErrorMessage("Please enter a valid string with number,small character and '-' as the special character and value should be less than 64 characters");
g_form.clearValue('Your_field_backend_name'); // please mention your field name here
}
}
Tried in my dev instance worked for me!
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 06:08 AM
Hi @Alon Grod ,
Below is the on submit client script you can try:
function onSubmit() {
var name = g_form.getValue('name');
var regex = /^[a-z0-9-]{1,64}$/;
if (!regex.test(name)) {
alert('Name can only contain small english letters, numbers and the symbol "-".');
return false; // prevent submission
}
return true; // allow submission
}
This script checks if the field value matches the regular expression ^[a-z0-9-]{1,64}$, which means:
^ start of string
[a-z0-9-] any small english letter, number or '-' symbol
{1,64} the string can be between 1 and 64 characters long
$ end of string
Regards,
Shravan.
Please mark this as helpful and correct answer, if this helps you
Shravan
Please mark this as helpful and correct answer, if this helps you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-15-2023 11:05 AM
Please check this solution if this is worked for you!
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.clearMessages();
var pattern = /^[a-z0-9-]*$/;
if (newValue.length > 64 || !(pattern.test(newValue))) {
g_form.addErrorMessage("Please enter a valid string with number,small character and '-' as the special character and value should be less than 64 characters");
g_form.clearValue('Your_field_backend_name'); // please mention your field name here
}
}
Tried in my dev instance worked for me!
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 02:48 AM