- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 12:08 AM
Dear Team,
I have a variable named 'customer_id' of type 'Single Line Text' on a catalog item. While filling out the form I want to make this field to take ONLY the below type format, the rest of any other format is not allowed and throws the error 'Please enter Valid Format'-
Format Required: NNNNN-NNN-NN-AAA (N denotes Numeric and A denotes Alphanumeric entries; In between '-' required, as shown in mentioned format).
I believe this requires OnCange Catalog CS on variable 'customer_id', but I am not able to get this fulfilled as '-' in between values and numeric and alphanumeric characters get me into trouble.
Requesting Help to get this resolved.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 01:05 AM
Hi @rishabh31
Use below on change client script on the text field. do replace the field name in script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var re = /^\d{5}-\d{3}-\d{2}-[a-zA-Z0-9]{3}$;
if (!re.test(newValue)) {
g_form.showFieldMsg('your_field name', 'Please enter valid format', 'error');
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 01:05 AM
Hi @rishabh31
Use below on change client script on the text field. do replace the field name in script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var re = /^\d{5}-\d{3}-\d{2}-[a-zA-Z0-9]{3}$;
if (!re.test(newValue)) {
g_form.showFieldMsg('your_field name', 'Please enter valid format', 'error');
return false;
}
return true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2023 01:34 AM
Hi @Manmohan K Thank you, tested and works well, just a small change in regex
var re = /^\d{5}-\d{3}-\d{2}-[a-zA-Z0-9]{3}$/;
Just applied '/' at last. Marking your solution correct and helpful.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 05:35 AM
@Manmohan K , there is an issue, the format required is: NNNNN-NNN-NN-AAA (N denotes Numeric and A denotes Alphanumeric entries; In between '-' required, as shown in mentioned format).
But the AAA part should be taking alphanumeric characters but it's taking all 3 alphabets or 3 Numerics, or 3 alphanumeric. Could you please change this only to take alphanumeric not only alphabets or only numerics.
Kindly help