Flyer
MB Enthusiast
I'm struggling with Regular Expressions - in fact they're driving me nuts
I have a small use for them and am about to give up entirely, but thought I'd ask here first.
I'm using them to validate postcode input. I have the following code (not mine):
This works great, but I would also like to allow just the outward part of the postcode to be entered, i.e. WA1, SW17.
I tried this:
but, it doesn't work. There's more code, and that could be the problem, but does that expression look OK? I've looked at it until I'm boggle-eyed
and it looks good to me
I could bone up on regexp, but I'm unlikely to need to use them again, so hopefully someone here can help. If not, I'll just dump it.
Cheers

I'm using them to validate postcode input. I have the following code (not mine):
Code:
var alpha1 = "[abcdefghijklmnoprstuwyz]"; // Character 1
var alpha2 = "[abcdefghklmnopqrstuvwxy]"; // Character 2
var alpha3 = "[abcdefghjkstuw]"; // Character 3
var alpha4 = "[abehmnprvwxy]"; // Character 4
var alpha5 = "[abdefghjlnpqrstuwxyz]"; // Character 5
Code:
// Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
// Expression for postcodes: ANA NAA
pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
// Expression for postcodes: AANA NAA
pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
I tried this:
Code:
// Expression for postcodes: AN, ANN, AAN, and AANN
pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})$","i"));


I could bone up on regexp, but I'm unlikely to need to use them again, so hopefully someone here can help. If not, I'll just dump it.
Cheers
