I am currently using jQuery and jquery ValidationEngine for the site, and it works like a charm. The problem is that I need to add the ability to check (and deny) PO code addresses. I looked around quite widely and could not find a regular expression that validationengine would use correctly.
I found a regex that works in Javascript:
\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b
but when I move this regular expression from the normal javascript function to the validationengine language file, the regular expression matches everything, even an empty entry in the text box.
regex i added in jquery.validationengine-en.js looks like this:
"notPoBox": { "regex": /\b[p]*(ost)*\.*\s*[o|0]*(ffice)*\.*\s*b[o|0]x\b/, "alertText": "* PO Box addresses are not allowed for shipping" },
and the form element uses the following:
<input class="validate[custom[notPoBox]] text-input" type="text" id="ship_add1" name="ship_add2" value="" style="width:598px;" />
Is there a way to make this regex work within the framework of validationengine and match correctly? I checked that the regex really works on my own javascript inside the page, since I can create a function that will match and warn about matches like this:
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 are unable to ship to a Post Office Box.\nPlease provide a different shipping address.'); return false; } });
I also checked it at http://www.regular-expressions.info/javascriptexample.html , which found matches as expected in a wide variety of entries (po box, po box, PO Box, etc.)
Any help would be appreciated.
Silvertiger