Data Validation: checkDate Function


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

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)


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.