Skip to content

Instantly share code, notes, and snippets.

@RhinoLu
Created August 25, 2012 07:22
Show Gist options
  • Save RhinoLu/3462037 to your computer and use it in GitHub Desktop.
Save RhinoLu/3462037 to your computer and use it in GitHub Desktop.
Validate URL 檢查URL是否有效
package
{
/**
* @link http://stackoverflow.com/questions/3455448/regex-url-problem
* @param _url
* @return
*/
public function ValidateURL(_url:String):String
{
var pattern:RegExp = new RegExp(
"\\b((?:https?://|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)"+
"(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\s()<>]+\\)))*\\))+"+
"(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|"+
"[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))",
"i" // case insensitive
)
var match:Array = _url.match(pattern);
if (match) {
return match[1];
}else {
return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment