RegularExpressionValidator expression help

J

John

Hi

I am using RegularExpressionValidator. What expression do I need to validate
these two;

Field1:

A9 9AA
A99 9AA
A9A 9AA
AA9 9AA
AA99 9AA
AA9A 9AA


Field 2:

99-99-99


A= Alphabets (A-Z, a-z)
9 = digits (0-9)

Thanks

Regards
 
G

Guest

Hi

I am using RegularExpressionValidator. What expression do I need to validate
these two;

Field1:

A9 9AA
A99 9AA
A9A 9AA
AA9 9AA
AA99 9AA
AA9A 9AA

Field 2:

99-99-99

A= Alphabets (A-Z, a-z)
9 = digits (0-9)

Thanks

Regards


1. ^([a-zA-Z]|\d){2,4}\s([a-zA-Z]|\d){2,3}$ // however it's not very
clear what the logic is here
2. ^\d\d-\d\d-\d\d$
 
J

John

Thanks Alexey. No 1 are the UK post codes.

Anon User said:
Hi

I am using RegularExpressionValidator. What expression do I need to
validate
these two;

Field1:

A9 9AA
A99 9AA
A9A 9AA
AA9 9AA
AA99 9AA
AA9A 9AA

Field 2:

99-99-99

A= Alphabets (A-Z, a-z)
9 = digits (0-9)

Thanks

Regards


1. ^([a-zA-Z]|\d){2,4}\s([a-zA-Z]|\d){2,3}$ // however it's not very
clear what the logic is here
2. ^\d\d-\d\d-\d\d$
 
J

John

The expression they have given;

^(GIR
0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY])|[0-9][A-HJKSTUW])
[0-9][ABD-HJLNP-UW-Z]{2})$

Is not accepted by the validator. Sorry I am a little weak on regular
expressions.

Thanks

Regards
 
G

Guest

The expression they have given;

^(GIR
0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HIK-Y][0-9](|[0-9]|[ABEHMNPRVWXY])|[0-9][A-H­JKSTUW])
[0-9][ABD-HJLNP-UW-Z]{2})$

Is not accepted by the validator. Sorry I am a little weak on regular
expressions.

Thanks

Regards




ok, it means you could use more precise expression
a) because A-Z, not a-z
b) format has some defined logic such as AA9 9AA or AA9A 9AA
Check this article
http://www.answers.com/topic/uk-postcodes- Hide quoted text -

- Show quoted text -


..NET has own syntax, I'm not sure but from the first look the problem
is somewhere with OR (|||)

Take a look at first expression

[A-Z]{1,2}[0-9R][0-9A-Z]?\s[0-9][A-Z]{2}

("\s" means a single space, and should be used in .NET)

This expression is working and short enough. If you want to accept
address of Santa

Do this

[A-Z]{1,2}[0-9R][0-9A-Z]?\s[0-9][A-Z]{2}|SAN\sTA1

By adding carat (^) at the beginning and dollar sign ($) at the end
the regex will only match if it contains the postal code

Regarding complexity: I don't think that this is neccessary to incl.,
for example, all used letters, or something like this. Anyhow there is
no way to check by regex if given postal code is related to given
city, or given area. In my opinion it should just check if the size of
the string is correct and string has proper format, e.g. space in the
middle and this will be enough.
 

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