Regular Expression Validator

B

Bryce Budd

Hi all,

I am trying to use a regular expression validator to check
for the existence of PO Box in an address textbox. The
business rule is "No addresses with PO Boxes are allowed."

What I want to happen is the Regular Expression Validator
to return false only when the string contains PO Box.
Currently it is false even when a valid address exists.

I need this validation to occur on the client, hence the
Regular Expression Validator control.

Here's the RE: I'm using in the ValidationExpression
property:

[^(P\.?\s?O\.?\sBox)+]

This currently matches (returns false/invalid) for:
smith road and smith po box road?

Any insight into the proper regular expression to achieve
my goal would be greatly appreciated.


Thanks in advance,

Bryce
 
B

Brian Davis

Try this one out:

(?i)^((?<!P\.?\s?O\.?\sBox).)+(?<!P\.?\s?O\.?\sBox)$

The (?i) turns on the ignore case option and then the expression matches the
beginning of the string, followed by 1 or more characters that are not
preceded by P.O. Box, followed by the end of the string. The repeated
negative look-behind is there to make sure that a string containing only
"P.O. Box" is not matched.


Brian Davis
www.knowdotnet.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top