- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 07:23 AM
Hello,
I have a catalog client script to validate a phone number format that looks like this.
It's an OnChange script applied for All UI types
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var pattern = /^\(\d{3}\)\s\d{3}-\d{4}$/; //(xxx) xxx-xxxx
var phone = g_form.getValue('phone_number');
if (!pattern.test(phone)) {
phone = phone.replace(/\D/g, '');
var regex = /^\d{10}$/;
var is_valid = regex.test(phone);
g_form.showErrorBox('phone_number', 'Invalid phone number. Please enter 10 digits');
if (!is_valid) {
g_form.addInfoMessage('Invalid phone number. Please enter 10 digits');
//g_form.showErrorBox('phone_number', 'test');
g_form.clearValue('phone_number');
} else {
phone = '(' + phone.slice(0, 3) + ') ' + phone.slice(3, 6) + '-' + phone.slice(6, 10);
g_form.setValue('phone_number', phone);
}
}
}
The script works fine when I use the 'g_gorm.addInfoMessage' but when I use the 'g_form.showErrorBox' (commented in the script) it doesn't work and I don't understand why...
Anybody can help?
Thank you
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 07:29 AM
Hi,
Have you checked both portal and back-end UI, just to see if it's showing back-end but not Portal?
I see where you said you had the UI Type set to ALL, but just curious if this is one of those "it works in back-end, but not portal, and I was only checking portal" type of scenarios? Haha.
Would you consider using show field message, but of error type?
g_form.showFieldMsg('phone_number', 'Invalid phone number. Please enter 10 digits', 'error');
Don't forget, you'd also want to code for removing that as well with "hideFieldMsg".
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 07:29 AM
Hi,
Have you checked both portal and back-end UI, just to see if it's showing back-end but not Portal?
I see where you said you had the UI Type set to ALL, but just curious if this is one of those "it works in back-end, but not portal, and I was only checking portal" type of scenarios? Haha.
Would you consider using show field message, but of error type?
g_form.showFieldMsg('phone_number', 'Invalid phone number. Please enter 10 digits', 'error');
Don't forget, you'd also want to code for removing that as well with "hideFieldMsg".
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 08:09 AM
Thank you. Now it work!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-15-2020 07:31 AM
Hey,
Try without using single quote on test
g_form.showErrorBox('phone_number', test);
OR
Use this --> g_form.showFieldMsg("phone_number","This is the error","error");
Please mark correct and helpful.
Thanks
Tanushree