Skip to content
Loading
How to use data-mask in textbox format(dd/mm/yyyy)
  • Jaganathan Bantheswaran
    I am not sure how you have tried. But this should work for you,
    1. <input type="text" required="" pattern="(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d" value="" >  
     Reference: http://html5pattern.com/Dates
  • thanks for reply ,
     
    but in this situation only after
    dd  add '/' 
    mm   add '/'
    yyyy add '/' 
     
     
    but i want to when enter more then month like i am enter 22/22/2222 show the error because this formate wrong right format is 22/12/2222 
     
    In case of only accept blow and equal to12 
     
    please  give any solution.............. 
  • Sanjeeb Sapkota
    here is sample code for your solution:
    1.     type="text"  
    2.     name="date"  
    3.     placeholder="dd/mm/yyyy"  
    4.     onkeyup="  
    5.         var v = this.value;  
    6.         if (v.match(/^\d{2}$/) !== null) {  
    7.             this.value = v + '/';  
    8.         } else if (v.match(/^\d{2}\/\d{2}$/) !== null) {  
    9.             this.value = v + '/';  
    10.         }"  
    11.     maxlength="10"  
    12. >