-
- /**
- *Regular expression matching any URL
- *bbs.it-home.org at 20130509
- */
- function IsURL(urlString)
- {
- regExp = /^((https?|ftp|news):/ /)?([a-z]([a-z0-9-]*[..
- ])+([a-z]{2}|aero|arpa|biz|com|coop|edu|gov|info|int| jobs|mil|museum|name|nato|net|org|pro|travel)|(([0-9]|[1-9][0-9]|1[0-9]{2}|2[ 0-4][0-9]|25[0-5]).){3}([0-9]|[1-9]
- [0-9]|1[0-9]{2} |2[0-4][0-9]|25[0-5]))(/[a-z0-9_-.~]+)*(/([a-z0-9_-.]*) (?[a-z0-9+_-.%=&]*)?)?(#[a-z][a-z0-9_]*)?$/
- if (urlString.match(regExp))
- return "is a url";
- else
- return "not a url";
- }
- url = "";
- alert(IsURL(url));
Copy code
Interested Friends, you can find a software to test the performance of this code.
No matter how good the regularity is, it is not recommended to use it if its performance is too poor.
|