The CreatorCon Call for Content is officially open! Get started here.

Restriction to filed If not start with specific letters

Sirri
Tera Guru

Hi All,

 

I have requirement as per the below:

We have one field( Machine Name). For that field restriction as per the below:

Text can only be 9 characters long. Cannot contain special characters or spaces. Must start with 'RTH'. If validation is not followed, an error message pops up ""Machine Name must start with RTH and is 9 characters long"" and the text should be clear .

 

Please provide the code. How can I achieve this.

Thank you.

1 REPLY 1

Hemanth M1
Giga Sage
Giga Sage

Hi @Sirri ,

 

Try this - Onsubmit client script

  // Regular expression for validation
    var regex = /^RTH[a-zA-Z0-9]{6}$/;
    // Validate the machine name
    if (!regex.match(g_form.getValue("Replace the field"))) {
		g_form.addErrorMessage("Machine Name must start with RTH and is 9 characters long");
		return false;
	}

 

Ex:

HemanthM1_0-1727179175259.png

Output 😍:

HemanthM1_1-1727179248283.png

 

Hope this helps!!!

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025