url有効チェック
1040 ワード
/**
* URL
* @param str_url
* @returns {boolean}
*/
function isURL(str_url) {
// url
var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" //
ftp user@ + "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP URL- 199.194.52.184
+ "|" // IP DOMAIN( )
+ "([0-9a-z_!~*'()-]+\.)*" // - www.
+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." //
+ "[a-z]{2,6})" // first level domain- .com or .museum
+ "(:[0-9]{1,4})?" // - :80
+ "((/?)|" // a slash isn't required if there is no file name
+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
var re = new RegExp(strRegex);
return re.test(str_url);
}
//
functionisURL(str) {
return !! str.match(/(((^https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)$/g);
}