我想验证网址。
它应该接受:
http://google.com
http://www.google.com
www.google.com
google.com
我指的是 Regex to match URL 。
但它不支持
google.com
。 最佳答案
如果不存在,只需在 http://
前面加上,然后进行测试。
if (inputURL.substring(0,7) != 'http://' && inputURL.substring(0,8) != 'https://') {
inputURL = 'http://' + inputURL;
}
不需要大型库或任何东西,只需几行代码。
关于javascript - 如何验证网址?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8660209/