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

@saranyavs 

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

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

Tejas Adhalrao
Kilo Sage

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

 

Tanushree Maiti
Giga Sage

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.

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: