I have this code:
HTML
<input type="text" data-value="1" data-type="input-records" placeholder="Value" pattern="\d{1,4}$" />
CSS
input[type=text]:invalid { background-color: red; }
Javascript
$("[data-type=input-records]").die().live("keypress", function (e) {
if (!($(this).val().length + 1) < 5) {
e.preventDefault();
return;
}
// More code below...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
I have this code:
HTML
<input type="text" data-value="1" data-type="input-records" placeholder="Value" pattern="\d{1,4}$" />
CSS
input[type=text]:invalid { background-color: red; }
Javascript
$("[data-type=input-records]").die().live("keypress", function (e) {
if (!($(this).val().length + 1) < 5) {
e.preventDefault();
return;
}
// More code below...
});
I want to make a validation like this:
if (!$(this).hasSelector(":invalid")) {
showMessage("Invalid value");
}
Use the is
function to test for the :invalid
pseudoclass:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
Example: http://jsbin.com/ikuwur/2/edit