Regular Expression help for limitting ranges
Hi, I am working on making a text field limited to dates, this is just a portion of the code. I already have validation of dates, but I am now trying to limit what the user enters by using a regular expression. This code works slightly however, it doesn't limit me for example I can enter in more than 2 digits but then it limits based on the total allowed so for example 8 digits are allowed if I just type. I need it to stop after the first 2 digits then have a - then 2 more digits then a - and then followed by 4 digits. I've tried limited each section and grouping as well. Any help would be greatly appreciated. Thanks.
This is in the format code and I am calling it in Keystroke.
function DateKS (){
var value = AFMergeChange(event);
if (!event.willCommit) {
// Only allow characters that match the regular expression
event.rc = /^([0]{0,1}[1-9]{0,1}|[1]{0,1}[012]{0,1})([-]{0,1})([0]{0,1}[1-9]{0,1}|[12]{0,1}[0-9]{0,1}|[3]{0,1}[01]{0,1})([-]{0,1})([0-9]{0,4})$/.test(value);
}
}