Created
August 25, 2012 07:22
-
-
Save RhinoLu/3462037 to your computer and use it in GitHub Desktop.
Validate URL 檢查URL是否有效
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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