- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 09:41 PM
Hi,
We have a catalog form which used in Service portal.
We have zip code field and phone number field.
Now, zip code and phone numbers are allowing letters in to that fields. We need to restrict to enter letters in zip and phone numbers.
Only valid zip code and phone numbers should be entering in to that.
How to achieve this?
I have tried below code but its not working, can anyone help me on this please?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearMessages();
var name = g_form.getValue('former_address_zip'); // Replace your ZIP Code Field
if(name == "")
return;
var regex = /^[0-9-+()]*$/;
if(!regex.test(name)) {
g_form.showFieldMsg('former_address_zip', 'Please Enter valid number', 'error');// Replace your ZIP Code Field
g_form.clearValue('former_address_zip');// Replace your ZIP Code Field
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2022 02:05 AM
Hi,
then you need to use script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
g_form.clearMessages();
if(oldValue != newValue){
var regex = /^[0-9-+()]*$/;
if(!regex.test(name)) {
g_form.clearValue('former_address_zip');// Replace your ZIP Code Field
g_form.showFieldMsg('former_address_zip', 'Please Enter valid number', 'error');// Replace your ZIP Code Field
}
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 09:51 PM
Hi,
so single variable can hold phone number and zip both?
why not have 2 different variables?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 09:55 PM
Its two different variables Ankur.
Zip code is different and Phone number is different.
Now, for both we need to restrict letters.
Could you please help me on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 10:25 PM
Hi,
so which zip code? US or India? because the regex would be different as both are having different zip formats
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 11:24 PM
Hi Ankur,
Any update please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2022 09:52 PM
Hi,
which Zip Code? India or US?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader