Html:
<form method="post" id="form">
<div class="row">
<div class="col-md-12">
<input type="text" id="labelSubject" class="form-control" data-field="subject">
<label for="labelSubject">Only upper-case *</label>
<div class="valid-message"></div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary" type="submit">CHECK</button>
</div>
</div>
</form>
JavaScript:
<script>
var form = $('#form').formValid({
fields: {
"name": {
"required": true,
"tests": [
{
"regex": "^[A-Z]+$",
"message": "Only upper-case letter"
}
]
}
}
});
form.keypress(300);
$('button[type="submit"]').click(function() {
form.test();
if (form.errors() == 0) {
alert('Ok');
}
return false;
});
</script>