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
- <script type="text/javascript">
- $(document).ready(function () {
- $(".gst").change(function () {
- var inputvalues = $(this).val();
- 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}$');
- if (gstinformat.test(inputvalues)) {
- return true;
- } else {
- alert('Please Enter Valid GSTIN Number');
- $(".gst").val('');
- $(".gst").focus();
- }
- });
- });
- </script>
-
- ASP Textbox
- <asp:TextBox ID="txtGST" MaxLength="15" runat="server" class="gst form-control mandatory" ClientIDMode="Static" placeholder="GST Reg No."></asp:TextBox>
-
- Html input type text
- <input type="text" class="gst" >