Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. $(function() {
  2.  
  3. $(".msgBtn").click(function() {
  4.  
  5. var isValid = true;
  6.  
  7. if (!$("#startDate").valid()) {
  8. isValid = false;
  9. }
  10. if (!$("#endDate").valid()) {
  11. isValid = false;
  12. }
  13.  
  14. if (!isValid)
  15. return;
  16.  
  17. $("form#csr-message").submit(); //save button
  18. });
  19. });
  20. $.validator.addMethod(
  21. "formatdata",
  22. function(value, element) {
  23. var i = /(?:0[1-9]|[12][0-9]|3[01]).(?:0[1-9]|1[0-2]).(?:19dd|20dd)/;
  24. return this.optional(element) || i.test(value);
  25. }, "Incorrect format data");
  26.  
  27. var validator = $("#csr-message")
  28. .validate(
  29. {
  30. rules : {
  31. startDate : {
  32. formatdata : true
  33.  
  34. },
  35. endDate : {
  36. formatdata : true
  37. }
  38. },
  39. messages : {
  40. startDate : {
  41. formatdata : jQuery
  42. .format("Start date has incorrect format!"),
  43. },
  44. endDate : {
  45. formatdata : jQuery
  46. .format("End date has incorrect format!"),
  47. }
  48. }
  49. }
  50.  
  51. $(function () {
  52. $.datepicker.setDefaults({
  53. dateFormat: 'dd/mm/yy'
  54. });
  55. });
  56.  
  57. Then to bind it to the input element:
  58. $(function () {
  59. $("#StartDate").datepicker();
  60. });
  61.  
  62. $(document).ready(function () {
  63. $('#btn_move').click( function(){
  64. var dateformat = /^(0?[1-9]|[12][0-9]|3[01])[/-](0?[1-9]|1[012])[/-]d{4}$/;
  65. var Val_date=$('#txt_date').val();
  66. if(Val_date.match(dateformat)){
  67. var seperator1 = Val_date.split('/');
  68. var seperator2 = Val_date.split('-');
  69.  
  70. if (seperator1.length>1)
  71. {
  72. var splitdate = Val_date.split('/');
  73. }
  74. else if (seperator2.length>1)
  75. {
  76. var splitdate = Val_date.split('-');
  77. }
  78. var dd = parseInt(splitdate[0]);
  79. var mm = parseInt(splitdate[1]);
  80. var yy = parseInt(splitdate[2]);
  81. var ListofDays = [31,28,31,30,31,30,31,31,30,31,30,31];
  82. if (mm==1 || mm>2)
  83. {
  84. if (dd>ListofDays[mm-1])
  85. {
  86. alert('Invalid date format!');
  87. return false;
  88. }
  89. }
  90. if (mm==2)
  91. {
  92. var lyear = false;
  93. if ( (!(yy % 4) && yy % 100) || !(yy % 400))
  94. {
  95. lyear = true;
  96. }
  97. if ((lyear==false) && (dd>=29))
  98. {
  99. alert('Invalid date format!');
  100. return false;
  101. }
  102. if ((lyear==true) && (dd>29))
  103. {
  104. alert('Invalid date format!');
  105. return false;
  106. }
  107. }
  108. }
  109. else
  110. {
  111. alert("Invalid date format!");
  112.  
  113. return false;
  114. }
  115. });
  116. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement