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