daily pastebin goal
33%
SHARE
TWEET

Untitled

a guest Jan 13th, 2018 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $.validator.addMethod('daterange', function(value, element, arg) {
  2.      // Same as above
  3.  
  4.      var startDate = Date.parse(arg[0]),
  5.          endDate = Date.parse(arg[1]),
  6.          enteredDate = Date.parse(value);      
  7.      // Same as below
  8.  
  9.  }, $.validator.format("Please specify a date between {0} and {1}."))
  10.    
  11. $.validator.addMethod('daterange', function(value, element) {
  12.     if (this.optional(element)) {
  13.         return true;
  14.     }
  15.  
  16.     var startDate = Date.parse('2010-11-29'),
  17.         endDate = Date.parse('2010-12-15'),
  18.         enteredDate = Date.parse(value);
  19.  
  20.     if (isNan(enteredDate)) {
  21.         return false;
  22.     }
  23.  
  24.     return ((startDate <= enteredDate) && (enteredDate <= endDate));
  25. });
  26.    
  27. if(isNaN(enteredDate)) return false;
  28.  
  29.     return ((startDate <= enteredDate) && (enteredDate <= endDate));
  30. }, "Please specify a date between 2010-11-29 and 2010-12-15");
  31.    
  32. $.validator.addMethod('dateRange', function (value, element, parameterValue) {
  33.         if (this.optional(element) && !value) {
  34.             return true;
  35.         }
  36.         var dateFormat = $(element).datepicker('option', 'dateFormat');
  37.         try {
  38.             var startDate = $.datepicker.parseDate(dateFormat, parameterValue[0]).getTime();
  39.             var endDate = $.datepicker.parseDate(dateFormat, parameterValue[1]).getTime();
  40.             var enteredDate = $.datepicker.parseDate(dateFormat, value).getTime();
  41.             return (startDate <= enteredDate) && (enteredDate <= endDate);
  42.         } catch (error) {
  43.             return true;
  44.         }
  45.     });
  46.    
  47. $.validator.addMethod('daterange', function(value, element, arg) {
  48.     if (this.optional(element) && !value) {
  49.         return true;
  50.     }
  51.  
  52.     var startDate = Date.parse(arg[0]),
  53.         endDate = Date.parse(arg[1]),
  54.         enteredDate = Date.parse(value);
  55.  
  56.     if (isNaN(enteredDate)) {
  57.         return false;
  58.     }
  59.  
  60.     return ( (isNaN(startDate) || (startDate <= enteredDate)) &&
  61.              (isNaN(endDate) || (enteredDate <= endDate)));
  62.  
  63.  
  64.    }, $.validator.format("Please specify a date between {0} and {1}."));
  65.    
  66. $("#some_date_input").rules("add",{daterange:['01/31/2001','01/31/2020']});
RAW Paste Data
Top