views:

226

answers:

1

i have a input datetime format: dd/mm/yy hh:mm

i use jquery validate to check user' input & it work well.

but now, i want validate hh:mm must not in a definite range, example:

i have blocking time from 07:00 to 15:00, so hh:mm user input must not in this range.

how to validate this using javascript (jquery validate, ...).

Thanks.

+1  A: 

Using plain Javascript:

<script>
    function validate_time(t,st,et){
       t = t.split(/:/);
       st = st.split(/:/);
       et = et.split(/:/);
       return (t[0] < st[0] 
            || t[0] > et[0] 
            || (t[0] == st[0] && t[1] < st[1])
            || (t[0] == et[0] && t[1] > et[1]));
    }

    // Call like:
    validate_time("08:00","07:00","15:00");
</script>
cmptrgeekken