Validate Calendar Date with RegExp


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  1. public function checkDate(date:String):Boolean
  2. {
  3. var month:String = "(0?[1-9]|1[012])";
  4. var day:String = "(0?[1-9]|[12][0-9]|3[01])";
  5. var year:String = "([1-9][0-9]{3})";
  6. var separator:String = "([.\/ -]{1})";
  7.  
  8. var usDate:RegExp = new RegExp("^" + month + separator + day + "\\2" + year + "$");
  9. var ukDate:RegExp = new RegExp("^" + day + separator + month + "\\2" + year + "$");
  10.  
  11. return (usDate.test(date) || ukDate.test(date) ? true:false);
  12. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.