Posted By

Activetuts on 11/19/10


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Demian
gudeidea
elderhsouza


Data Validation: checkDate Function


 / Published in: ActionScript 3
 

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

Today, almost everything on the web is based on user input. A contact form, a user registration form, a search box and so on. As a developer you can’t just rely on the user to write everything as it’s supposed to be. To be sure you always get the correct data from your users you will need to validate the input. (By Enabled)

  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.