Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Regular Expression to validate Incident number

sri26
Giga Contributor

Hi Team,

Can anyone share the regular expression code to validate incident number in Snow.

I'm trying as below:

var userTI = "INC\d{7}";

Its not working!

Please help

 

Thanks,

Sri

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

var str = 'INC0012345';
var regex = /^INC\d{7}$/;
var val = regex.test(str);
gs.info(val);

Output:

find_real_file.png

Regards
Ankur

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

try this

var str = 'INC0012345';
var regex = /^INC\d{7}$/;
var val = regex.test(str);
gs.info(val);

Output:

find_real_file.png

Regards
Ankur

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

Community Alums
Not applicable

Hi,

the regex should be like:

 

var regex = /INC\d{7}/g;

then you can just use regex.test(STRING TO TEST)

 

Cheers,

Joro