Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. $('#dateBirth').keyup(function(event){
  2.  
  3. var val = $(this).val().toString();
  4. var patt = /[^0-9]/g;
  5. var pure = val.replace(patt,"");
  6. $(this).val(pure);
  7. var val = $(this).val().toString();
  8.  
  9. var maxLength = Number($(this).attr('maxlength'));
  10.  
  11. if((event.which > 47 && event.which < 58) || (event.which > 95 && event.which < 105)) {
  12. if(val.length >= maxLength){
  13. if($(this)[0].id == $('#dateBirth')[0].id){
  14. $('#monthBirth').focus();
  15. }
  16. else if($(this)[0].id == $('#monthBirth')[0].id){
  17. $('#yearBirth').focus();
  18. }
  19. }
  20. }
  21.  
  22. if(val.length > maxLength){
  23. val = val.substring(0, maxLength);
  24. $(this).val(val);
  25. }
  26.  
  27. }).blur(function(){
  28.  
  29. if ($(this).val() != "") {
  30. if ($(this).val() < 1) {
  31. $(this).val("1");
  32. } else {
  33. if (($(this)[0].id == $('#dateBirth')[0].id) && $(this).val() > 31){
  34. $(this).val("31");
  35. }
  36. else if (($(this)[0].id == $('#monthBirth')[0].id) && $(this).val() > 12){
  37. $(this).val("12");
  38. }
  39. else if (($(this)[0].id == $('#yearBirth')[0].id) && $(this).val() > 9999){
  40. $(this).val("9999");
  41. }
  42. }
  43. var val = $(this).val().toString();
  44. var length = val.length;
  45. var maxLength = Number($(this).attr('maxlength'));
  46. if (length < maxLength) {
  47. var i;
  48. for (i = 0; i < (maxLength - length); i++) {
  49. var val = $(this).val().toString();
  50. $(this).val('0' + val);
  51. }
  52. }
  53. }
  54.  
  55. });
  56.  
  57. <div class="labelFieldWrapper dateBirth">
  58. <input type="text" size="20" maxlength="2" id="dateBirth" name="birthDay" value="" class="inputElem js_movePlaceholder" />
  59. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement