Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

how to check single line text should contain data in format "firstname lastname"

saranyavs
Tera Expert

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

7 REPLIES 7

vaishali231
Tera Guru

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

 

 

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



Ankur Bawiskar
Tera Patron

@saranyavs 

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! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

This is for new account creation, hence reference field cannot be used.

and the variabe is used for orchestration for AD account creation.