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
hey @saranyavs
Create a Catalog Client Script
Type: onSubmit
UI Type: All
Script:
function onSubmit() {
var name = g_form.getValue('name'); // variable name
// Regex
var regex = /^[A-Za-z]+ [A-Za-z]+$/;
if (!regex.test(name)) {
g_form.showFieldMsg('name', 'Please enter value in format: Firstname Lastname', 'error');
return false;
}
return true;
}
*************************************************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
hey @saranyavs
Hope you are doing well.
Did my previous reply answer your question?
If it was helpful, please mark it as correct ✓ and close the thread . This will help other readers find the solution more easily.
Regards,
Vaishali Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
why are you expecting user to remember any person's first name and last name while entering?
why not use reference variable?
What's your actual business requirement? what's that form used for? what that variable used for?
💡 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
This is for new account creation, hence reference field cannot be used.
and the variabe is used for orchestration for AD account creation.
