2014-01-15 2 views
-1

URL의 유효성을 검사하려면 정규식이 필요합니다. 잘못된 URL 형식에 따라정규식을 사용하여 URL 유효성을 검사하십시오.

http://example.com 
http://example.com/index.php 
http://example.com/index.php#test 
http://example.com/demo/index.php 
http://example.com/demo/index.php#test 
http://www.example.com 
http://wwww.example.com 
https://www.example.com 
https://wwww.example.com 

됩니다 :

://example.com 
http://example.com/index..php 
http://example.com/index.php###test 
http://example.com/de,mo/index.php 
http://example.com/de!mo/index.php#test 
http://ww.example.com 
http://wwwww.example.com 
htps://www.example.com 
https:/wwww.example.com 
http://wwww.example.com/.,.,. 
http://wwww.exa_mple.com/ 
+0

를 참조하십시오 다음
은 유효한 URL 형식입니다 : http://stackoverflow.com/questions/161738/what-is-the-be st-regular-expression-to-a-string-of-a-valid-url –

+0

http://example.com/index..php, http://example.com/index를 고려해야합니다. .php ### test, http : //example.com/.. ,,. 무효로합니다. – SoftProdigy

+0

왜 http://ww.example.com은 잘못된 URL인가요? 물론, "보통"당신은 "www"를 기대할 것입니다, 그러나 그것은 완전히 유효하며 어떤 테스트를 통과해야합니다. 숙제가 있니? – ygoncho

답변

0

이 SO에 대한 자주 묻는 질문이

var url = "http://www.example.com"; 
var url_regx = /^(ht|f)tps?:\/\/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/; 

if(url.match(url_regx)) 
{ 
    alert("matched"); 
} 
else 
{ 
    alert("unmatched"); 
} 

DEMO

+0

http://example.com/index..php, http://example.com/index.php###test, http : //www.example.com /.,.,.,. 기타 – SoftProdigy

관련 문제