Copy link to clipboard
Copied
Hi all,
I wonder if you could help with the following. I'm looking to build a banner advert for a client that allows users to input their details in order to receive a free guide sent through to their email address / have the option to enter their phone number for a call about the promotion.
I've cracked the email validation (i think), however I'm having a few problems validating phone numbers before they are approved and sent for data collection. I have found the following tutorial online (http://active.tutsplus.com/tutorials/actionscript/validating-various-input-data-in-flash/) which provides you with the following code;
However, this is for US phone numbers I think and I'm looking to either have it UK based or preferably allow all telephone numbers to be validated (is this possible?). Currently the form on the tutorial page does not allow for standard UK landline and mobile phone numbers - how would I do this?
public function checkPhoneNumber(phoneNumber:String😞Boolean
{
var countryCode:String = "((\\+|00)?([1-9]|[1-9][0-9]|[1-9][0-9]{2}))";
var num:String = "([0-9]{3,10})";
phoneNumber = phoneNumber.match(/[\+\d]/g).join('');
var phone:RegExp = new RegExp("^" + countryCode + num +"$");
return phone.test(phoneNumber);
}
Thanks in advance for the help. If you would like any further information let me know. The code above is located in a seperate AS file and is the key part that has to be altered, but see below for what is inside the movie clip.
James
var validator:Validator = new Validator();
stage.addEventListener(FocusEvent.FOCUS_IN, register);
stage.addEventListener(FocusEvent.FOCUS_OUT, unregister);
function register(e:FocusEvent):void
{
e.target.addEventListener(Event.ENTER_FRAME, onFrameUpdate, false, 0, true);
}
function unregister(e:FocusEvent):void
{
e.target.removeEventListener(Event.ENTER_FRAME, onFrameUpdate);
}
function onFrameUpdate(e:Event):void
{
var input:String = e.target.text;
var valid:Boolean;
switch(e.target)
{
case emailField.input_txt:
valid = validator.checkEmailAddress(input);
break;
case phoneNumberField.input_txt:
valid = validator.checkPhoneNumber(input);
break;
}
if(valid)
e.target.parent.validTick.gotoAndStop('valid');
else e.target.parent.validTick.gotoAndStop('invalid');
}
Copy link to clipboard
Copied
there are a few regular expressions here you can look at maybe one of these will help
http://regexlib.com/UserPatterns.aspx?authorid=d95177b0-6014-4e73-a959-73f1663ae814
this looks the most promising
^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more