"Input Validation + Colorful Input Groups"
Bootstrap 3.1.0 Snippet by p4r41b4

<link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.1.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <!--<div class="panel panel-default">--> <div class="row"> <div class="col-md-8"> <form method="post"> <div class="form-group"> <label for="validate-select">Coordenador(a) Administrativo(a):</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Coordenador(a) Administrativo(a):" required> <option value="">Selecione:</option> <option value="item_1">Lucimara Pereira</option> <option value="item_2">Divino Santos</option> <option value="item_3">Marcio Sidião</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Coordenador(a) TI:</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Coordenador(a) TI:" required> <option value="">Selecione:</option> <option value="item_1">Carlos Roberto Gomes Jr.</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Coordenador(a) Solicitante:</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Coordenador(a) Solicitante:" required> <option value="">Selecione:</option> <option value="item_1">Adriano</option> <option value="item_2">Divino Santos</option> <option value="item_2">Lorena Conte</option> <option value="item_2">Lucimara Pereira</option> <option value="item_2">Luiz Junior</option> <option value="item_3">Max Blenner</option> <option value="item_3">Marcio Sidião</option> <option value="item_2">Orlando Camara</option> <option value="item_2">Vanilson Oliveira</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Funcionario:</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Funcionario:" required> <option value="">Selecione:</option> <option value="item_1">Francisco Jorge</option> <option value="item_2">Marcio Alex David</option> <option value="item_3">Camilla Monteiro</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Departamento:</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Departamento:" required> <option value="">Selecione:</option> <option value="item_1">Administrativo</option> <option value="item_2">Contabilidade</option> <option value="item_3">Tecnologia da Informação</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Cargo Funcionario:</label> <div class="input-group"> <select class="form-control" name="validate-select" id="validate-select" placeholder="Cargo Funcionario:" required> <option value="">Selecione:</option> <option value="item_1">Analista I</option> <option value="item_2">Analista Contabil</option> <option value="item_3">Analista de TI</option> </select> <span class="input-group-addon danger"><span class="glyphicon glyphicon-remove"></span></span> </div> </div> <div class="form-group"> <label for="validate-select">Email:</label> <div class="input-group"> <span class="input-group-addon"> @ </span> <input class="form-control" placeholder="Email" name="email" type="email" required="" autofocus=""> </div> </div> </form><!--./form --> </div><!-- col-md-8 --> </div><!-- ./row --> </div><!-- ./contanier -->
.input-group-addon.primary { color: rgb(255, 255, 255); background-color: rgb(50, 118, 177); border-color: rgb(40, 94, 142); } .input-group-addon.success { color: rgb(255, 255, 255); background-color: rgb(92, 184, 92); border-color: rgb(76, 174, 76); } .input-group-addon.info { color: rgb(255, 255, 255); background-color: rgb(57, 179, 215); border-color: rgb(38, 154, 188); } .input-group-addon.warning { color: rgb(255, 255, 255); background-color: rgb(240, 173, 78); border-color: rgb(238, 162, 54); } .input-group-addon.danger { color: rgb(255, 255, 255); background-color: rgb(217, 83, 79); border-color: rgb(212, 63, 58); }
$(document).ready(function() { $('.input-group input[required], .input-group textarea[required], .input-group select[required]').on('keyup change', function() { var $form = $(this).closest('form'), $group = $(this).closest('.input-group'), $addon = $group.find('.input-group-addon'), $icon = $addon.find('span'), state = false; if (!$group.data('validate')) { state = $(this).val() ? true : false; }else if ($group.data('validate') == "email") { state = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test($(this).val()) }else if($group.data('validate') == 'phone') { state = /^[(]{0,1}[0-9]{3}[)]{0,1}[-\s\.]{0,1}[0-9]{3}[-\s\.]{0,1}[0-9]{4}$/.test($(this).val()) }else if ($group.data('validate') == "length") { state = $(this).val().length >= $group.data('length') ? true : false; }else if ($group.data('validate') == "number") { state = !isNaN(parseFloat($(this).val())) && isFinite($(this).val()); } if (state) { $addon.removeClass('danger'); $addon.addClass('success'); $icon.attr('class', 'glyphicon glyphicon-ok'); }else{ $addon.removeClass('success'); $addon.addClass('danger'); $icon.attr('class', 'glyphicon glyphicon-remove'); } if ($form.find('.input-group-addon.danger').length == 0) { $form.find('[type="submit"]').prop('disabled', false); }else{ $form.find('[type="submit"]').prop('disabled', true); } }); $('.input-group input[required], .input-group textarea[required], .input-group select[required]').trigger('change'); });

Related: See More


Questions / Comments: