GST Number Validation using Javascript or jQuery

Introduction

This post explains GST number validation using Javascript or jQuery on a text change event. You need to apply the "gst" class to control and add the below Javascript function.

GST no sample : 05ABDCE1234F1Z2

Code

  1. <script type="text/javascript">      
  2. $(document).ready(function () {      
  3. $(".gst").change(function () {    
  4.                 var inputvalues = $(this).val();    
  5.                 var gstinformat = new RegExp('^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]1}[1-9A-Z]{1}Z[0-9A-Z]{1}$');    
  6.                 if (gstinformat.test(inputvalues)) {    
  7.                     return true;    
  8.                 } else {    
  9.                     alert('Please Enter Valid GSTIN Number');    
  10.                     $(".gst").val('');    
  11.                     $(".gst").focus();    
  12.                 }    
  13.             });          
  14.  });          
  15.   </script>      
  16.       
  17. ASP Textbox        
  18. <asp:TextBox ID="txtGST" MaxLength="15" runat="server" class="gst form-control mandatory" ClientIDMode="Static" placeholder="GST Reg No."></asp:TextBox>          
  19.         
  20. Html input type text        
  21. <input type="text" class="gst" >