I need to do user validation of a date field, it should be in the format yyyyMMdd and should not be more than one year in the future. How would I go about doing this? Currently I only have a crude regexp which is insufficient.
function VerifyDate(source, args) { var regexp = /^([1-2]{1}[0-9]{1})\d{2}([0][1-9]|[1][0-2])([0][1-9]|[1-2][0-9]|[3][0-1])$/ var result = args.Value.match(regexp); if(result) { args.IsValid = true; } else { args.IsValid = false; } }
Take the regex to check the format only. You can stay simple:
Then parse the date and check the range: