Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

Regex expression validation is not working

snow57
Tera Contributor

Hi, 

 

The regex validation in the below code is not working. could someone please help me on this .

 

 

var nonPrint = "123Test*input";
gs.print('nonPrint1'+nonPrint);
var regex =/^[0-9][0-9]*$/;
var s = nonPrint.replace(regex, '_');
gs.print('nonPrint2' + s);

 

Appreciate for the leads.

 

Thanks

5 REPLIES 5

@snow57 Use Escape character (\) to match with a reserved letter of regex.

For example if you wish to match $ then it would be written as \$ if you wish to match / then it should be written as \/ if you wish to match \ then it should be written as // in the regular expression.

 

var nonPrint = "123Test*input";
gs.print('nonPrint1 '+nonPrint);
var regex =/^[0-9][0-9]*\$/;
var s = nonPrint.replace(regex, '_');
gs.print('nonPrint2 ' + s);

Hope this helps.