Skip to content

Instantly share code, notes, and snippets.

@vanillajonathan
Created September 22, 2015 17:28
Show Gist options
  • Save vanillajonathan/81234cee3dd023f14191 to your computer and use it in GitHub Desktop.
Save vanillajonathan/81234cee3dd023f14191 to your computer and use it in GitHub Desktop.
Input validation with Bootstrap warning
<div class="form-group">
<label class="control-label" for="url">URL</label>
<input class="form-control" type="url" id="url" placeholder="https://api.example.com/" />
<p class="help-block" id="url-help"></p>
</div>
$('#url').on('input', function (e) {
if ($(this).val().startsWith("http://")) {
$(this).parent().addClass('has-warning');
$('#url-help').text('Note that the communication will not be secure.');
} else {
$(this).parent().removeClass('has-warning');
$('#url-help').text(null);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment