How can i be able to ensure that a selected date time value is between a given time range.
i.e
2/2/2011 8:10:30 is invalid but
2/2/2011 8:30:00 is a valid date
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Regular expressions match strings, not numbers or number ranges. Therefore you need to think about the textual representation of all valid times/dates and analyze them.
A number between 5 and 11 would therefore be
1[01]|[5-9]etc.; this can get arbitrarily complex with dates, especially if you need to validate user input. Then your regex needs to know about leap years and all that – all of which is possible but nightmarish to maintain. So you really need to think about if it’s really a regex you want…For the range
8:30:00-13:00:00you get (written here as a verbose regex):See why this isn’t a good idea?