Return to Snippet

Revision: 38518
at January 4, 2011 12:02 by Activetuts


Initial Code
public function checkDate(date:String):Boolean
{
    var month:String        = "(0?[1-9]|1[012])";
    var day:String          = "(0?[1-9]|[12][0-9]|3[01])";
    var year:String         = "([1-9][0-9]{3})";
    var separator:String    = "([.\/ -]{1})";
 
    var usDate:RegExp = new RegExp("^" + month + separator + day + "\\2" + year + "$");
    var ukDate:RegExp = new RegExp("^" + day + separator + month + "\\2" + year + "$");
 
    return (usDate.test(date) || ukDate.test(date) ? true:false);
}

Initial URL
http://active.tutsplus.com/tutorials/actionscript/validating-various-input-data-in-flash/

Initial Description
From the tutorial, Validating Various Input Data in Flash (http://active.tutsplus.com/tutorials/actionscript/validating-various-input-data-in-flash/)

Initial Title
Validate Calendar Date with RegExp

Initial Tags
date, regexp, validation

Initial Language
ActionScript 3