Return to Snippet

Revision: 26227
at April 21, 2010 05:54 by adrianparr


Initial Code
var inputPostcode:String = "dn3 6gb";
trace("inputPostcode: "+inputPostcode);
var checkedPostcode:String = validateUkPostcode(inputPostcode).toUpperCase();

if (checkedPostcode == "") {
	trace("No valid postcode was found");
} else {
	trace("checkedPostcode: "+checkedPostcode);
}



function validateUkPostcode(str:String):String {
	var returnString:String;
	var pattern:RegExp = /[a-zA-Z]{1,2}[1-9]{1}[0-9]?([ ]{1}[0-9]{1}[a-zA-Z]{2})/g;
	var result:Object = pattern.exec(str);
	if(result == null) {
		returnString = "";
	} else {
		returnString = result[0];
	}
	return returnString;
}

Initial URL
http://regexlib.com/REDetails.aspx?regexp_id=260

Initial Description

                                

Initial Title
AS3 Checks and Returns Valid UK Postcode using Regular Expression

Initial Tags
regex, format, regexp, uk

Initial Language
ActionScript 3