javascript - validate whether continuous weekdays checkbox are checked -


i have checkboxes below shows days of week.

enter image description here

the value of checkboxes 1, 2, 3, 4, 5, 6, 7 respectively.

i need have validation logic in javascript validates whether user clicks checkboxes continuous days. continuous days can start day. like,

wednesday, thursday, friday, saturday, sunday (4,5,6,7,1)

monday, tuesday, wednesday, thursday, friday, saturday(2,3,4,5,6,7)

saturday, sunday, monday, tuesday, wednesday, thursday(7,1,2,3,4,5)

tuesday, wednesday, thursday, friday, saturday, sunday(3,4,5,6,7,1) etc.

minimum of 5 days should selected. user should not allowed select below examples:

saturday, sunday, monday, wednesday, thursday(7,1,2,4,5)

monday, wednesday, thursday, friday, saturday(2,4,5,6,7)

tuesday, thursday, friday, saturday, sunday(3,5,6,7,1)

is there way handle validation in javascript/jquery?

if can selected values array then

function test(values){      if(values.length !=5 ){         return false;     }      var expected = values[0], valid = true;     $.each(values, function(i, v){         if( expected != v){             valid = false;             return false;         }         expected  = v == 7 ? 1 : v + 1;     })      if(!valid){         return false;     }      return true; } 

demo: fiddle


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -