I am trying to test a input string of format AWT=10:15;, based on this regex that I wrote: (([AWT]\w\S=)?(\d{0,9}:)?(\d{0,9});).
Problem 1: I am receiving this error: Uncaught TypeError: Cannot read property '0' of undefined when I try to match the string with the regex.
Problem 2: The string seems to come off as valid even after I enter this: AWT=10:15;12 which shouldn't be the case.
Here is my code:
var reg = new RegExp('(([AWT]\w\S=)?(\d{0,9}:)?(\d{0,9});)');
var x = $('td').find('.awt')[0].value;
console.log(x); // AWT=10:15;
console.log(String(x).match(reg)); // [";", ";", undefined, undefined, "", index: 9, input: "AWT=10:15;", groups: undefined]
if(String(x).match(reg)){
console.log("valid");
}else{
console.log("Invalid")
}
I was wondering if anyone can help me figure out the right regex for the string.
PS: The string needs to be in that exact format: (AWT=[0,9]:[0,9];).