Showing posts with label Validation. Show all posts
Showing posts with label Validation. Show all posts

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

Validation using Javascript, jQuery using the class

Introduction
Validation using Javascript, jQuery using the class name.
You just need to add class 'mandatory' in control then this control will be required for submission of the form. if it is not filled then it will be red highlighted.

Code
  1. function Validation() {    
  2. var isValid = true;    
  3. var classname = 'mandatory';    
  4. $('.' + classname + '').each(function (i, obj) {    
  5. if (obj.value == '') {    
  6. isValid = false;    
  7. return isValid;    
  8. }    
  9. });  
  10.   
  11. if (!isValid) {    
  12. $('.' + classname + '').each(function (i, obj) {    
  13. if (obj.value == '') {    
  14. obj.style.border = '1px solid red';    
  15. }    
  16. else {    
  17. obj.style.border = '1px solid black';    
  18. }    
  19. });    
  20. alert('Please fill mandatory details');    
  21. }    
  22. if (isValid) {    
  23. return confirm('Are you sure you want to save information? Once information stored will not be updated.')    
  24. }    
  25. return isValid;    
  26. }    
  27.   
  28. for ex.    
  29.   
  30. ASP textbox : <asp:TextBox ID="txtlocation" runat="server" CssClass="form-control mandatory"></asp:TextBox>     
  31. html input text : <input class="mandatory" type="text">