servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2025 11:41 PM - last edited Wednesday
............................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2025 12:08 AM
Hello @umar5 ,
You can try the below onChange client script that converts Indian format (1234567890) to US fromat (123-456-7890).
Script -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Remove any non-digit characters from the input
var cleanNumber = newValue.replace(/\D/g, '');
// Check if the cleaned number is exactly 10 digits
if (/^\d{10}$/.test(cleanNumber)) {
// Format the number into US format: 123-456-7890
var formattedNumber = cleanNumber.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
// Set the formatted number back to the field
g_form.setValue('mobile_no', formattedNumber);
} else {
// Display an error message if the input is not valid
g_form.addErrorMessage('Please enter a valid 10-digit mobile number.');
g_form.clearValue('mobile_no');
}
}
Output -
Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.
Thanks and Regards,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2025 02:01 AM
@umar5 ,
Have you tried using this provided script? If it doesn’t work, please let me know. I’ll be happy to assist further!
Thanks,
Ashish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2025 12:34 AM
why?
what's your business requirement?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2025 12:58 AM
Hope you are doing well !
I have a string field called Phone number when user enters the phone number in indian format it should convert into US format. Can you please help me in this?
Thanks & Regards,
Umar Shaik.