-1

Running this code in JSFiddle results in a "no problem" for "l" but a "problem" for "m", even though both variables appear to be the same format. https://jsfiddle.net/zj8mg518/26/

    var errString;
    var l = "JLF5J-383Z3-QQKWR-JEN3T-39NUT-3";
    var m = "12345-12345-12345-12345-A";

    function Check_License_Key_Format(license) {
        var regexLicense = new RegExp("^([A-za-z0-9]{5}[-]){5}[A-Za-z0-9]$");
        return regexLicense.test(license);
    }

    if (Check_License_Key_Format(l) == false)
        errString = "problem";
    else
        errString = "no problem";            
    alert(errString);

      if (Check_License_Key_Format(m) == false)
        errString = "problem";
    else
        errString = "no problem";
    alert(errString);
Gio
  • 4,099
  • 3
  • 30
  • 32

1 Answers1

2

Let's read your regex, shall we?

"Five groups of (five letters/numbers followed by a hyphen) followed by a letter/number"

I only count 4 groups in the m variable. So it fails.


Separately, you have A-z rather than A-Z near the beginning. It should be A-Z.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592