Text box should start with '_'

mohammedhyderal
Kilo Contributor

Hi All,

I have a requirement of placing a validation   in the text box,

It should start with '_A' , If not it should throw as error

16 REPLIES 16

Hi,



Can you please help me with the script


Try below in onChange catalog client script.



Also check below blog for better understanding:-



https://community.servicenow.com/community/blogs/blog/2016/10/04/lets-learn-little-about-regular-exp...



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


------------------------------------------------------------------------


function onChange(control, oldValue, newValue, isLoading) {


    if (isLoading || newValue == '') {


          return;


    }



var regexp = /^_a.*$/;

// alert(regexp.test(newValue));
    if(!regexp.test(newValue)){


  alert("It should start with _A");


  g_form.setValue('u_impacted_users', '');


  }


}


Hi Mohammed,



Can you mark my reply as helpful/correct since the regular expression for validation was shared in the question from my end.



Thanks


Ankur


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

ya thanks


Deepa Srivastav
Kilo Sage

Is it solved? if yes pls mark Correct to close the thread and make it helpful for others who have same issue in future.


You can find correct option by clicking on below link.



Text box should start with '_'