简体   繁体   English

使用javascript验证并将http和/或www添加到字符串

[英]Validate and add http and/or www to string using javascript

in javascript I get a string that should be something like: 在JavaScript中,我得到的字符串应该是这样的:

(also third level and lower domains) (也是第三级和下级域)

I need that 1st the string is validate, 2nd if the string isn't in the third case (http://www.website.tld/something), it has to concat "http://" and/or "www". 我需要第一个字符串是有效的,第二个如果字符串不在第三种情况下(http://www.website.tld/something),则必须连接“ http://”和/或“ www” 。

Anyone has some tip or knows where to find a ready-to-use script that implement this? 任何人都有技巧或知道在哪里可以找到实现此目的的现成脚本?

我将使用正则表达式进行匹配以查看您应采取的措施。

If you use jQuery (or can use it), I recommend the excellent validator plugin which has a built-in function which validates jQuery Validate 如果您使用jQuery(或可以使用它),我建议使用出色的验证器插件,该插件具有用于验证jQuery Validate的内置函数。

It's easy to use, and works well 它易于使用,并且运行良好

DISCLAIMER: I am not involved in this project nor knowing the creator. 免责声明:我没有参与这个项目,也不认识创建者。 Just a simple satisfied user ;-) 只是一个简单的满意的用户;-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM