Posted By

Activetuts on 01/04/11


Tagged

date regexp validation as3


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

chus
elderhsouza
dubogii


Validate Calendar Date with RegExp


 / Published in: ActionScript 3
 

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

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

  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. }

Report this snippet  

You need to login to post a comment.