Skip to content
Loading
How to validate error message on web form?  
  •   
  •   
  • class="row">  
  •    class="col-md-6 ">  
  •       class="input-group pull-right">  
  •                                           
  •          @Html.TextBoxFor(m => m.HomeMainModel.Address, new { @class = "form-control", type = "text",  id="inputFormVal", autofocus = "autofocus", placeholder = "Street Address Line 2", required = "required" })  
  •          class="input-group-append">  
  •             class="input-group-text">  
  •               
  •            
  •         
  •      
  •    class="col-md-6">  
  •       "labelMessageBx" class="text-danger" style="display:none">  
  •      
  •   
  •   
  • 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 = "inputFormVal", autofocus = "autofocus", placeholder = "City" })             
  •             @Html.TextBoxFor(m => m.HomeMainModel.Code, new { @class = "form-control", type = "text", id = "inputFormVal", autofocus = "autofocus", placeholder = "Province" })  
  •            
  •         
  •      
  •    class="col-md-6">  
  •       "labelMessageBx" 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 = "inputFormVal",  
  •             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">  
  •          "labelMessageBx" class="text-danger" style="display:none">  
  •         
  •      
  •   
  • ```  
  •       
  • ```javascript  
  • // function when leaving texbox for city, street address, street_address_line2, state_province.  
  • $(function() {  
  •   $('#inputFormVal').blur(function() {  
  •     var city = document.getElementById("inputFormVal").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("labelMessageBx").style.display = "inline";  
  •     } else {  
  •       document.getElementById("labelMessageBx").style.display = "none";  
  •     }  
  •   });  
  • });  
  • ```  
  •  

    2 Replies

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