Posted By

Activetuts on 01/04/11


Tagged

phone number regexp validation telephone as3


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

chus
nyong15
elderhsouza
dubogii


Validate a Phone Number 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 checkPhoneNumber(phoneNumber:String):Boolean
  2. {
  3. var countryCode:String = "((\\+|00)?([1-9]|[1-9][0-9]|[1-9][0-9]{2}))";
  4. var num:String = "([0-9]{3,10})";
  5. phoneNumber = phoneNumber.match(/[\+\d]/g).join('');
  6. var phone:RegExp = new RegExp("^" + countryCode + num +"$");
  7.  
  8. return phone.test(phoneNumber);
  9. }

Report this snippet  

You need to login to post a comment.