jQuery ValidationEngine and PO Box -
i using jquery , jquery validationengine site, , works charm. issue need add ability check (and dis-allow) p.o. box addresses. have looked around quite extensively , have not been able find regex validationengine use.
i did find regex works in javascript:
\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b
but when move regex normal javascript function validationengine language file regex matches on everything, blank entry in text field.
the regex added jquery.validationengine-en.js follows:
"notpobox": { "regex": /\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b/, "alerttext": "* p.o. box addresses not allowed shipping" },
and form element uses following:
<input class="validate[custom[notpobox]] text-input" type="text" id="ship_add1" name="ship_add2" value="" style="width:598px;" />
is there way can regex work within validationengine framework , match properly? have verified regex indeed work on own javascript within page can create function match , alert on matches follows:
function pochk() { $("[id*='ship_add1']").blur(function() { var pattern = new regexp('\\b[p]*(ost)*\\.*\\s*[o|0]*(ffice)*\\.*\\s*b[o|0]x\\b', 'i'); if ($("[id*='ship_add1']").val().match(pattern)) { alert('we unable ship post office box.\nplease provide different shipping address.'); return false; } });
i checked @ http://www.regular-expressions.info/javascriptexample.html found matches expected on wide variety of entries (p o box, po box, p.o. box, etc.)
any appreciated.
silvertiger
when define custom validation, regex
test validate value matches expression , generate validation error if not.
the way have defined, notpobox
passes when value is a po box value.
you need check opposite of match regex.
you using function , returning negated value of regex test()
:
"notpobox": { "func": function (field, rules, i, options) { var ispobox = /\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b/i; return !ispobox.test(field.val()); }, "alerttext": "* p.o. box addresses not allowed shipping" },
Comments
Post a Comment