null或Domain(Pattern)验证的正则表达式 [英] Regular Expression for null or Domain (Pattern) validation
本文介绍了null或Domain(Pattern)验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
什么是检查字符串是否是有效URL的最佳正则表达式?
我想通过正则表达式验证文本框。它应该是空的或有效的域名像Google.com example.com。
Thx
解决
的有效网址
函数isValidURL(url)
{
return url.match(/([a-zA-Z] +:\ / \ /)?(.+ \。)?(\w +)(\.\w + :[0-9] +)?(\ /.+)?/)?真假;
}
alert(isValidURL(document.getElementById('textBoxId')。value));
它不适用于像example.com这样的东西,因为这些不是有效的 在这个意义上的urls。 http://
的有效网址
Possible Duplicate:
What is the best regular expression to check if a string is a valid URL?
I want to validate text box by regular expression. It should be Null or valid Domain Name Like Google.com, example.com.
Thx
解决方案
Something along the following lines will work.
function isValidURL(url)
{
return url.match(/([a-zA-Z]+:\/\/)?(.+\.)?(\w+)(\.\w+)(:[0-9]+)?(\/.+)?/) ? true : false;
}
alert(isValidURL(document.getElementById('textBoxId').value));
It won't work for things like "example.com" as really these aren't "valid" urls in that sense. A valid url beings with http://
这篇关于null或Domain(Pattern)验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文