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");
}
Share
Improve this question
asked Jan 17, 2013 at 17:22
Sergio FloresSergio Flores
5,4275 gold badges38 silver badges60 bronze badges
1 Answer
Reset to default 28Use the is
function to test for the :invalid
pseudoclass:
if ($(this).is(":invalid")) {
showMessage("Invalid value");
}
Example: http://jsbin.com/ikuwur/2/edit