You need to check for anchors (^
and $
forcing the check at the beginning and end of the string) as well, not just the patterns.
^\d{4}-[a-z]{4}-\d{5}$
Use with i
option to ignore letter case.
Sample code:
var re = /^\d{4}-[a-z]{4}-\d{5}$/i;
var str="1234-abcd-12345";
if (re.test(str)) {
alert("found");
}
solved Not able to get Regular Expression in javascript