Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to validate the text entered in a field should start with \\ using client script

ss123
Tera Contributor

Hi all,

 

We need to validate the text/character entered in a single line text field type to

always start with this special character  " \\ "

 

Can you help me do it using client script? Thanks!

1 ACCEPTED SOLUTION

Gangadhar Ravi
Giga Sage

Hi @ss123 

 

You can implement onChange client script. below is example, I tried this on short description field and it is working fine.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   if (newValue && !newValue.startsWith("\\")) {
        // If it doesn't start with '\', display an error message and clear the field
        alert('The value must start with the "\\" character.');
        g_form.clearValue('short_description');  // Optional: Clear the value to force re-entry
    } 

   //Type appropriate comment here, and begin script below
   
}

 Please mark my answer correct and helpful if this works for you.

View solution in original post

3 REPLIES 3

Gangadhar Ravi
Giga Sage

Hi @ss123 

 

You can implement onChange client script. below is example, I tried this on short description field and it is working fine.

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
   if (newValue && !newValue.startsWith("\\")) {
        // If it doesn't start with '\', display an error message and clear the field
        alert('The value must start with the "\\" character.');
        g_form.clearValue('short_description');  // Optional: Clear the value to force re-entry
    } 

   //Type appropriate comment here, and begin script below
   
}

 Please mark my answer correct and helpful if this works for you.

Mani A
Tera Guru

var name= g_form.getValue('name'); 

 if (!name.startsWith('\\')) {

        g_form.addErrorMessage('The input of name must start with  \\');  

or use alert(");

    }

@ss123  please accepted as solution and helpful if it resolved