I have a site that is being built in ASPX. Unfortunately, because of this fact, I cannot actually use the <form>
tag to wrap my inputs, and as far as I can see, jQuery Validation Plugin only supports validating inputs within a <form>
. Is there any way to validate these inputs, using the specified rules, on keyup
without having them wrapped in a <form>
tag?
$(function() {
$('.form-container').validate({
rules: {
useremail: {
required: true,
email: true
},
userstate: {
required: true,
maxlength: 2
}
},
messages: {
useremail: 'Please enter a valid email',
userstate: 'Please enter your state',
}
});
$('.form-container input').on('keyup', function() {
$(this).validate();
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.18.0/jquery.validate.min.js"></script>
<div class="form-container">
<input type="text" name="useremail" placeholder="Email" />
<input type="text" name="userstate" placeholder="State" maxlength="2" />
</div>