how to check single line text should contain data in format "firstname lastname"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi team,
In catalog item there is a field called 'name' as single line text, this should allow data only in below format. how to write the script ?
Firstname<space>Lastname
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
then how would you know which is firstname and which is last name?
User can give Abel Tuter or Tuter Abel
You don't have any source of truth to verify if Abel is firstname or lastname
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @saranyavs ,
you can write the on change client script for your name field.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '')
return;
var regex = /^[A-Za-z]+ [A-Za-z]+$/;
if (!regex.test(newValue)) {
g_form.showFieldMsg('u_name',
'Format must be: Firstname Lastname (Example: John Doe)',
'error'
);
} else {
g_form.hideFieldMsg('u_name');
}
}
If you found my solution helpful, please mark it as Helpful or Accepted Solution...!
thanks,
tejas
Email: adhalraotejas1018@gmail.com
LinkedIn: https://www.linkedin.com/in/tejas1018
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @saranyavs ,
Could you please explain the background on your requirement.
Do you have requested for variable (reference variable )in your form. Or you are placing Name text variable for that purpose.
Or based on other variable selection, you want to populate this name variable.
