本文介绍了jQuery PO BOX验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我浏览了一些较早的帖子,但对正在发生的事情仍然有些困惑.我有一个不允许使用PO Box的运输表格,所以我试图找到一个验证程序来查看并确保输入字段中没有PO.我确保每个字段都填充有此代码,但想知道如何将其包含在邮政信箱验证中.注意:这是与我的实际表格分开的文件

I have looked through some of the older posts and still a little confused with what is happening. I have a shipping form that DOES NOT allow PO Boxes so I am trying to find a validator to look through and make sure that input field doesnt have PO in it. I am making sure every field is filled out with this code but wondering how I could incorporate in the PO box validation with it.Note: this is a seperate file from my actual form

$( document ).ready(

    function()
    {
        $( '#shipping' ).submit(
            function()
            {

                    var required_fields = new Array(
                        'name',
                        'service',
                        'company',
                        'contact',
                        'street',
                        'city',
                        'state',
                        'zip',
                        'projectnum'
                    );


                        for( j in required_fields )
                        {

                            var theRequiredField = required_fields[j]
                            var inputField = $( '[name="' + theRequiredField + '"]' )

                            if( inputField.val() == '' )
                            {                                   
                                alert( "The '" + theRequiredField + "' field is required." );
                                inputField.focus();
                                return false;

                            } 

                        } 


            } // function
            ) // submit
    }

);  

推荐答案

也许有更好的方法,但这是我想出的:

There may be a better method, but here's what I came up with:

实时演示

Live Demo

$('input[name=address]').each(function() {
    var pattern = new RegExp('[PO.]*\\s?B(ox)?.*\\d+', 'i');
    if ($(this).val().match(pattern)) {
        $(this).after('<span class="pob">No PO Boxes</span>');
    }
});

这篇关于jQuery PO BOX验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 04:22