I am new to coding and I am not exactly sure what I am doing wrong here, but I am just to validate an input in a form against a few stock symbols. When I submit an symbol that isn't in the array, I do not receive the error message. My code is below.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.js"></script>
<script>
jQuery.validator.addMethod("vsymbol", function(value)
{
var symbols = ["GOOG", "AAPL", "MSFT", "DIS"];
var in_array = $.inArray(value.toUpperCase(), symbols);
if (in_array == -1)
{
return false;
}
else
{
return true;
}
}, "Not a valid stock symbol");
$("#myform").validate(
{
rules: {
symbol: {
required: true,
symbol: true
}
}
}
);
</script>
<body>
<form id="myform" >
<label for="symbol">Ticker</label>
<input name="symbol" type="text" class="vsymbol" />
</form>
</body>