JQuery URL验证器 [英] JQuery URL Validator
问题描述
全部,
我正在尝试使用JQuery的URL Validator插件。
I am trying to use JQuery's URL Validator plugin.
http:// docs。 jquery.com/Plugins/Validation/Methods/url
我有一个带有URL的文本框。我想编写一个获取文本框值的函数,使用jquery的验证器插件来验证URL并返回true或false。
I have a text box that has a URL. I want to write a function which takes the textbox value, uses the jquery's validator plugin to validate urls and returns true or false.
类似Ex:
function validateURL(textval)
{
// var valid = get jquery's validate plugin return value
if(valid)
{
return true;
}
return false;
}
我希望这是一个可重复使用的功能..
I wanted this to be a reusable function..
谢谢
推荐答案
验证()jQuery是为了验证表单本身我相信,不仅仅是一个单独的领域。
The validate() jQuery is made to validate a form itself I believe, not just an individual field.
如果您不尝试进行表单验证,我认为使用正则表达式来验证单个文本框会更好。
I think you would be better off using a regex to validate a single textbox if you are not trying to a do a form validation.
以下是SO问题的一个例子。
Here's an example of a SO question that works.
function validateURL(textval) {
var urlregex = new RegExp(
"^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([0-9A-Za-z]+\.)");
return urlregex.test(textval);
}
资料来源:此处
这篇关于JQuery URL验证器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!