First off please see my example in JSfidle:
http://jsfiddle.net/WMxKk/1/
You can see when you click submit it prevents you if the fields haven’t been filled out. But I also want to check if certain fields are an integer?
The current code I am using to check doesn’t seem to work:
else if (required[i] == "vidHeight" && intRegex.test(input.val())) {
// Check certain fields are positive intergers
input.addClass("needsfilled");
$('#' + required[i]).after('<p style="font-weight:bold;" id="' + required[i] + '_error">' + interror + '</p>');
errornotice.fadeIn(750);
The if statement on it’s own:
required[i] == "vidHeight" && intRegex.test(input.val())
Whats the best way to go ab out this?
Don’t you need to negate the regex? If it’s the attribute you’re looking for && it’s not a number, then show the error.