I'm writing a script to check if there's occurence of amex credit card number inside a string.
My code looks like this:
let amexRegex= /^3[47][0-9]{13}$/;
if(text.search(amexRegex) != -1){
console.log('Found!');
} else {
console.log('Not found!');
}
When I set textto '378734493671000' (a valid amex credit card number), script prints out Found!, but if I keep that same text and add some text arround it, like this: '378734493671000 ABCDEFG', it prints out Not found!.
What should I change in order to find occurence of substring matching the regex? I don't need a index of substring matching the regex, just true\false.