Validate a Phone Number 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 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. }

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.