1

I have the following RegEx that works well in Java Script but not in JScript. The only difference I found between the 2 is the that JScript uses /expression/ and tried it with no luck. I need to match specific string date format.

var pattern = "/([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))T(00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/";

var regexpattern = new RegExp(pattern); 

var str = "2018-02-28T17:05:10";   
var res = regexpattern.test(str);

//var res = str.match(pattern);
if ( res != null)
{
Log.Message("Test worked ");
}
else
{
Log.Message("did not");
}

EDIT: It should be declared as:

var pattern = /([12]\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01]))T(00|[0-9]|1[0-9]|2[0-3]):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9])$/;
fazlook1
  • 139
  • 2
  • 15

0 Answers0