- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 03:53 PM
Hello everyone
I'm trying to write this client script for the phone number on the application form. I look at the script. It seems to be right but i'm not sure why it's not doing anything. no error. Am I tripping or something else? please help. Thanks
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var phoneNumbReg = /^\d{3}-\d{3}-\d{4}$/;
if (!phoneNumbReg.test(newValue)) {
g_form.showFieldMsg('phone_number', 'Please enter a valid phone number', 'error');
g_form.clearValue('phone_number');
} else {
g_form.hideFieldMsg('phone_number');
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:16 PM
@huyjor : Please try with the below code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if (!pattern.test(newValue)) {
alert('Phone enter a valid phone number');
g_form.setValue('variable_name', '');
}
}
ServiceNow HI Article that tells the implementation steps in detail: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0719284
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:16 PM
Hi @huyjor
Are you sure that the field name is "phone_number"? Custom fields always start with the prefix "u_".
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 04:16 PM
@huyjor : Please try with the below code.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var pattern = /^[(]?(\d{3})[)]?[-|\s]?(\d{3})[-|\s]?(\d{4})$/;
if (!pattern.test(newValue)) {
alert('Phone enter a valid phone number');
g_form.setValue('variable_name', '');
}
}
ServiceNow HI Article that tells the implementation steps in detail: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0719284
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-25-2023 09:14 PM
@huyjor : Did my response address your question, or is there anything else I can help you with?
Please mark this as correct answer and helpful if it resolved, or mark this helpful if this help you to reach towards solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2023 09:27 PM
Hi @huyjor ,
Please refer the below link.
https://www.servicenow.com/community/developer-forum/mobile-number-validation/m-p/1866580
Mark my answer as accepted solution and helpful if helps you.
Thanks,
Nivedita Patil.