Skip to content
Loading
How to make all texbox when leaving have one label error mes  
  •                         class="col-md-6 col-sm-10 col-xs-10">  
  •                             "labelMessaget" class="text-danger" style="display:none">  
  •                           
  •                           
  •                         class="row">  
  •                             class="col-md-6 ">  
  •                                 class="input-group pull-right">  
  •                                                                      
  •                                     @Html.TextBoxFor(m => m.HomeMainModel.Address, new { @class = "form-control", type = "text", id = "address", autofocus = "autofocus", placeholder = "Street Address Line 2", required = "required" })  
  •                                     class="input-group-append">  
  •                                         class="input-group-text">  
  •                                           
  •                                       
  •                                   
  •   
  •                               
  •                           
  •   
  •   
  •        class="form-group">  
  •                             class="input-group mb-2">  
  •                                 class="input-group-prepend">  
  •   
  •                                   
  •   
  •                                 class="input-group col-md-7 col-md-offset-7 col-sm-7 col-xs-7">  
  •                                     class="input-group pull-right">  
  •                                                                        
  •                                         @Html.TextBoxFor(m => m.HomeMainModel.City, new { @class = "form-control", type = "text", id = "city", autofocus = "autofocus", placeholder = "City", required = "required" })               
  •   
  •                                         @Html.TextBoxFor(m => m.HomeMainModel.State, new { @class = "form-control", type = "text", id = "state", autofocus = "autofocus", placeholder = "State/ Province", required = "required" })  
  •   
  •                                         class="input-group-append">  
  •                                             class="input-group-text">  
  •                                               
  •                                           
  •                                       
  •                                   
  •                               
  •                             class="col-md-6 col-sm-10 col-xs-10">  
  •                                 "labelMessaget" class="text-danger" style="display:none">  
  •                               
  •   
  •   
  • class="input-group mb-2">  
  •                                 class="input-group-append">  
  •   
  •                                   
  •                                 class="input-group col-md-7 col-md-offset-3 col-sm-2 col-xs-2">  
  •                                     class="input-group pull-right">  
  •                                                            
  •                                                      
  •                                         @Html.TextBoxFor(m => m.HomeMainModel.Code, new  
  •                                    {  
  •                                        @class = "form-control",  
  •                                        type = "text",  
  •                                        id = "postal code",  
  •                                        autofocus = "autofocus",  
  •                                        placeholder = "Postal/Zip Code"  
  •   
  •                                         })  
  •                                                             
  •                                         @Html.DropDownListFor(m => m.HomeMainModel.SelectedCountryId, this.ViewBag.CountryList as SelectList, new { @class = "form-control" })  
  •                                         class="input-group-append">  
  •                                             class="input-group-text">  
  •   
  •                                               
  •                                           
  •   
  •                                       
  •                                   
  •                               
  •                           
  •                         class="col-md-6 col-sm-10 col-xs-10">  
  •                             "labelMessaget" class="text-danger" style="display:none">  
  •                           
  •   
  •   
  •   
  •         // function when leaving texbox for city, street address, street_address_line2, state_province.  
  •   
  •     $(function() {  
  •     $('#City').blur(function() {  
  •         var city = document.getElementById("City").value;  
  •         var expr = /^([\w-\.]+)@@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;  
  •         if (!expr.test(city)) {  
  •             document.getElementById("labelMessaget").style.display = "inline";  
  •         } else {  
  •             document.getElementById("labelMessaget").style.display = "none";  
  •         }  
  •     });  
  • });  
  •  

    3 Replies

    Know the answer? Post it — somebody with the same question will find it here.