/ Published in: ActionScript 3
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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; }
URL: http://regexlib.com/REDetails.aspx?regexp_id=260