Regular expression field validation in jQuery

In jQuery, is there a function/plugin which I can use to match a given regular expression in a string?

For example, in an email input box, I get an email address, and want to see if it is in the correct format. What jQuery function should I use to see if my validating regular expression matches the input?

I've googled for a solution, but I haven't been able to find anything.


I believe this does it:

http://bassistance.de/jquery-plugins/jquery-plugin-validation/

It's got built-in patterns for stuff like URLs and e-mail addresses, and I think you can have it use your own as well.


If you wanted to search some elements based on a regex, you can use the filter function. For example, say you wanted to make sure that in all the input boxes, the user has only entered numbers, so let's find all the inputs which don't match and highlight them.

$("input:text")
    .filter(function() {
        return this.value.match(/[^d]/);
    })
    .addClass("inputError")
;

Of course if it was just something like this, you could use the form validation plugin, but this method could be applied to any sort of elements you like. Another example to show what I mean: Find all the elements whose id matches /[az]+_d+/

$("[id]").filter(function() {
    return this.id.match(/[a-z]+_d+/);
});

我使用jQuery和JavaScript,它对我来说工作正常:

var rege = /^([A-Za-z0-9_-.])+@([A-Za-z0-9_-.])+.([A-Za-z]{2,4})$/;
if(rege.test($('#uemail').val())){ //do something }
链接地址: http://www.djcxy.com/p/92636.html

上一篇: 使用正则表达式匹配电子邮件地址

下一篇: jQuery中的正则表达式字段验证