×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Jing Tai Piao
Added: May 29, 2013 1:28 AM
Views: 21
Tags: no tags
  1. function IsURL(str_url){
  2. var strRegex = '^((https|http|ftp|rtsp|mms)?://)'
  3. + '?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?' //ftp user@
  4. + '(([0-9]{1,3}.){3}[0-9]{1,3}' // IP format URL- 199.194.52.184
  5. + '|' // 允许IP和DOMAIN(domain name)
  6. + '([0-9a-z_!~*'()-]+.)*' // domain name with  www.
  7. + '([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].' //
  8. + '[a-z]{2,6})' // first level domain- .com or .museum
  9. + '(:[0-9]{1,4})?' // port- :80
  10. + '((/?)|' // a slash isn't required if there is no file name
  11. + '(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$';
  12. var re=new RegExp(strRegex);
  13. //re.test()
  14. if (re.test(str_url)){
  15. return (true);
  16. }else{
  17. return (false);
  18. }
  19. }