Tuesday 7 January 2020

Bank IFSC code validation using Javascript or jquery

Introduction 

Here is a validation code for bank IFSC code.

IFSC code format : 
- Starting 4 should be only alphabets[A-Z]
Remaining 7 should be accepting only alphanumeric

Code



  1. <script type="text/javascript">  
  2. $(document).ready(function(){   
  3.       
  4. $(".ifsc").change(function () {    
  5. var inputvalues = $(this).val();    
  6.   var reg = /[A-Z|a-z]{4}[0][a-zA-Z0-9]{6}$/;  
  7.                 if (inputvalues.match(reg)) {  
  8.                     return true;  
  9.                 }  
  10.                 else {  
  11.                      $(".ifsc").val("");  
  12.                     alert("You entered invalid IFSC code");  
  13.                     //document.getElementById("txtifsc").focus();  
  14.                     return false;  
  15.                 }  
  16. });    
  17.   
  18. });  
  19. </script>  
  20.   
  21. IFSC : <input type="text" class="ifsc">  

PAN no validation using javascript or jquery

Introduction  

Here is a javascript code to validate PAN no.

PAN no sample : ABCDE1234F

Code


  1. <script type="text/javascript">  
  2. $(document).ready(function(){   
  3.       
  4. $(".pan").change(function () {    
  5. var inputvalues = $(this).val();    
  6.   var regex = /[A-Z]{5}[0-9]{4}[A-Z]{1}$/;  
  7.   if(!regex.test(inputvalues)){    
  8.   $(".pan").val("");  
  9.   alert("invalid PAN no");  
  10.   return regex.test(inputvalues);  
  11.   }  
  12. });    
  13.   
  14. });  
  15. </script>  
  16.   
  17. PAN : <input type="text" class="pan">  


Email id validation using jquery or javascript

Introduction

Here is a javascript function to validate email id.
you need to add class "email" in text control.

Code 


  1. <script type="text/javascript">      
  2. $(document).ready(function () {      
  3.   
  4. $(".email").change(function () {  
  5. var inputvalues = $(this).val();  
  6. var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;  
  7. if(!regex.test(inputvalues)){  
  8. alert("invalid email id");  
  9. return regex.test(inputvalues);  
  10. }  
  11. });  
  12.   
  13.  });          
  14. </script>          
  15.         
  16. Html input type text        
  17. Email : <input type="text" class="email" >  

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.        



Sunday 5 January 2020

Calculate sum or total of gridview rows in asp.net using jquery or javascript

Introduction 

Sum of asp gridview rows in asp.net using jquery or javascript.
All the textboxes are mandatory and only allowed number.

Code
  1. <script type="text/javascript">  
  2. $(document).ready(function () {  
  3.   
  4. $('.numberonly').keypress(function (e) {  
  5.   
  6. var charCode = (e.which) ? e.which : event.keyCode  
  7.   
  8. if (String.fromCharCode(charCode).match(/[^0-9]/g))  
  9.   
  10. return false;  
  11.   
  12. });  
  13.   
  14. });  
  15.   
  16. function sumBudgetedValues(ctrl) {  
  17.   
  18. var row = $(ctrl).closest('tr')[0];  
  19.   
  20. var strbudgetedval = row.cells[14].childNodes[1];  
  21.   
  22. var totalsum = 0;  
  23.   
  24. for (var i = 2; i < 14; i++) {  
  25.   
  26. totalsum += row.cells[i].childNodes[1].value == "" ? 0 : parseFloat(row.cells[i].childNodes[1].value);  
  27.   
  28. }  
  29.   
  30. var strname = '[name="' + strbudgetedval.name + '"]';  
  31.   
  32. $(strname).val(totalsum);  
  33.   
  34. }  
  35.   
  36. function Validation() {  
  37.   
  38. //validation for FIRM  
  39.   
  40. var isValid = true;  
  41.   
  42. var classname = 'mandatory';  
  43.   
  44. $('.' + classname + '').each(function (i, obj) {  
  45.   
  46. if (obj.value == '') {  
  47.   
  48. isValid = false;  
  49.   
  50. return isValid;  
  51.   
  52. }  
  53.   
  54. });  
  55.   
  56.   
  57.   
  58. if (!isValid) {  
  59.   
  60. $('.' + classname + '').each(function (i, obj) {  
  61.   
  62. if (obj.value == '') {  
  63.   
  64. obj.style.border = '1px solid red';  
  65.   
  66. }  
  67.   
  68. else {  
  69.   
  70. obj.style.border = '1px solid black';  
  71.   
  72. }  
  73.   
  74. });  
  75.   
  76. alert('Please fill mandatory details');  
  77.   
  78. }  
  79.   
  80. if (isValid) {  
  81.   
  82. return confirm('Are you sure you want to save information? Once information stored will not be updated.')  
  83.   
  84. }  
  85.   
  86.   
  87. return isValid;  
  88.   
  89. }  
  90.   
  91. </script>  
  1. <asp:GridView ID="gvdashboard" ClientIDMode="Static" runat="server" ShowHeaderWhenEmpty="true" EmptyDataText="No records found" EmptyDataRowStyle-ForeColor="Red"  
  2.   
  3. EmptyDataRowStyle-HorizontalAlign="Center" AllowPaging="True"  
  4.   
  5. AutoGenerateColumns="False" GridLines="Vertical" HeaderStyle-Wrap="false" BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px">  
  6.   
  7. <AlternatingRowStyle BackColor="#DCDCDC" />  
  8.   
  9.   
  10. <Columns>  
  11.   
  12. <asp:BoundField DataField="ID" HeaderText="ID" ControlStyle-CssClass="hidectrl" ItemStyle-CssClass="hidectrl" HeaderStyle-CssClass="hidectrl"></asp:BoundField>  
  13.   
  14. <asp:BoundField DataField="Month" HeaderText="Month" ItemStyle-Width="5px"></asp:BoundField>  
  15.   
  16. <asp:TemplateField HeaderText="Jan">  
  17.   
  18. <ItemTemplate>  
  19.   
  20. <asp:TextBox ID="txtjan" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  21.   
  22. </ItemTemplate>  
  23.   
  24. </asp:TemplateField>  
  25.   
  26. <asp:TemplateField HeaderText="Feb">  
  27.   
  28. <ItemTemplate>  
  29.   
  30. <asp:TextBox ID="txtfeb" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  31.   
  32. </ItemTemplate>  
  33.   
  34. </asp:TemplateField>  
  35.   
  36. <asp:TemplateField HeaderText="Mar">  
  37.   
  38. <ItemTemplate>  
  39.   
  40. <asp:TextBox ID="txtmar" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  41.   
  42. </ItemTemplate>  
  43.   
  44. </asp:TemplateField>  
  45.   
  46. <asp:TemplateField HeaderText="Apr">  
  47.   
  48. <ItemTemplate>  
  49.   
  50. <asp:TextBox ID="txtapr" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  51.   
  52. </ItemTemplate>  
  53.   
  54. </asp:TemplateField>  
  55.   
  56. <asp:TemplateField HeaderText="May">  
  57.   
  58. <ItemTemplate>  
  59.   
  60. <asp:TextBox ID="txtmay" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  61.   
  62. </ItemTemplate>  
  63.   
  64. </asp:TemplateField>  
  65.   
  66. <asp:TemplateField HeaderText="Jun">  
  67.   
  68. <ItemTemplate>  
  69.   
  70. <asp:TextBox ID="txtjun" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  71.   
  72. </ItemTemplate>  
  73.   
  74. </asp:TemplateField>  
  75.   
  76. <asp:TemplateField HeaderText="Jul">  
  77.   
  78. <ItemTemplate>  
  79.   
  80. <asp:TextBox ID="txtjul" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  81.   
  82. </ItemTemplate>  
  83.   
  84. </asp:TemplateField>  
  85.   
  86. <asp:TemplateField HeaderText="Aug">  
  87.   
  88. <ItemTemplate>  
  89.   
  90. <asp:TextBox ID="txtaug" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  91.   
  92. </ItemTemplate>  
  93.   
  94. </asp:TemplateField>  
  95.   
  96. <asp:TemplateField HeaderText="Sep">  
  97.   
  98. <ItemTemplate>  
  99.   
  100. <asp:TextBox ID="txtsep" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  101.   
  102. </ItemTemplate>  
  103.   
  104. </asp:TemplateField>  
  105.   
  106. <asp:TemplateField HeaderText="Oct">  
  107.   
  108. <ItemTemplate>  
  109.   
  110. <asp:TextBox ID="txtoct" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  111.   
  112. </ItemTemplate>  
  113.   
  114. </asp:TemplateField>  
  115.   
  116. <asp:TemplateField HeaderText="Nov">  
  117.   
  118. <ItemTemplate>  
  119.   
  120. <asp:TextBox ID="txtnov" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  121.   
  122. </ItemTemplate>  
  123.   
  124. </asp:TemplateField>  
  125.   
  126. <asp:TemplateField HeaderText="Dec">  
  127.   
  128. <ItemTemplate>  
  129.   
  130. <asp:TextBox ID="txtdec" runat="server" CssClass="form-control nopadding numberonly mandatory" onchange="sumBudgetedValues(this)"></asp:TextBox>  
  131.   
  132. </ItemTemplate>  
  133.   
  134. </asp:TemplateField>  
  135.   
  136. <asp:TemplateField HeaderText="Total">  
  137.   
  138. <ItemTemplate>  
  139.   
  140. <asp:TextBox ID="txttotal" runat="server" CssClass="form-control nopadding" ReadOnly="true"></asp:TextBox>  
  141.   
  142. </ItemTemplate>  
  143.   
  144. </asp:TemplateField>  
  145.   
  146. </Columns>  
  147.   
  148. <EditRowStyle BackColor="#2461BF" />  
  149.   
  150. <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />  
  151.   
  152. <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  
  153.   
  154. <PagerStyle CssClass="pagination-ys" />  
  155.   
  156. <RowStyle BackColor="#EFF3FB" />  
  157.   
  158. <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />  
  159.   
  160. <SortedAscendingCellStyle BackColor="#F5F7FB" />  
  161.   
  162. <SortedAscendingHeaderStyle BackColor="#6D95E1" />  
  163.   
  164. <SortedDescendingCellStyle BackColor="#E9EBEF" />  
  165.   
  166. <SortedDescendingHeaderStyle BackColor="#4870BE" />  
  167.   
  168. </asp:GridView>  
  169.   
  170.   
  171. <asp:Button ID="btnsubmit" CssClass="btn-lg btn-primary" OnClientClick="return Validation();" runat="server" Text="Submit" OnClick="btnsubmit_Click" />  
  172.   
  173.