I just fixed your double-quotes and it worked
<html>
<head>
<script type="text/javascript">
function validate() {
var valStreet = new RegExp("[pP]{1}[.]*[oO]{1}[.]*[ ]*[bB]{1}[oO]{1}[xX]{1}"); //Anything with "PO BOX" alerted
if (form.Street.value.match(valStreet) != null) {
alert("No P O Box Allowed in Shipping Address.");
}
}
</script>
</head>
<body>
<?php
$street = 'ez';
?>
<form name="test">
Street:
<?php print "<input type=\"text\" name=\"street\" onBlur=\"validate();\" value=\"$street\" >"; ?>
<!--<input type="text" name="street" value="" onBlur="validate();">-->
<br>
<input type="button" name="test" value="test">
</form>
</body>
</html>
Did you know that with regular expressions you can do a case-insensitive modifier and not have to do
dB type stuff.
Something like this ...
.match( /p.*?o.*?b.*?o.*?x.*/i );
...should work, but RegEx is always tricky and I didn't actually test the above
For that matter, you could probably get away with just this ...
.match( /.*?box/i ); // pobox, po box, post office box, mail box, postal box (all in upper and/or lower case)
Enjoy