-1

The following code always generates the $ is undefined alert message.

Here is the code for the Script tag:

function CheckString() {
  try {
    var s = "";
    s = $('#regExString').val();
    alert(s);
    var regExpression = /^[A-Z,a-z]\d[A-Z,a-z][\s{1}]?\d[A-Z,a-z]\d/;

    if (regExpression.test(s))
      alert("Valid postal code.");

    else
      alert("Invalid postal code.");

  } catch (e) {
    alert(e.message);
  }
}

The html input text tag is passed as the text field and a button has this function (CheckString) as its on click function which validates the regular expression

Moishe Lipsker
  • 2,974
  • 2
  • 21
  • 29

1 Answers1

0

This is because jQuery has not been imported into your web solution.

In your HTML file in between your head tags, add this:

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
</head>
nashcheez
  • 5,067
  • 1
  • 27
  • 53