Tuesday 7 January 2020

GST number validation using javascript or jquery

Introduction 
GST number validation using Javascript or jquery on text change event.
you need to apply "gst" class to control and add 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" >      
  22.        



1 comment: