Nice one, Ian :)

Without the extras, here's a regex for UK post codes:
/^[A-Z]{1,2}\d[\dA-Z]?\s?\d[A-Z]{2}$/i
and one for UK phones (includes mobiles):
^\\s*\\(?(020[7,8]{1}\\)?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}
[0-9]{3}\\)?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\\s*\$

Made these ages ago & have forgotten how - but they work. Done for PHP
- is javascript regex different?

On Apr 20, 8:47 pm, Ian <[EMAIL PROTECTED]> wrote:
> I've noticed a lot of requests for Postal Code validation. I don't
> know if anyone posted one, but here is an addon method I wrote for
> Canadian postal codes.
>
> $.validator.addMethod("postalCode", function(value) { // Addon method
> for validating postal codes. Valid formats are (X1X 1X1) or (X1X1X1)
> or (X1X-1X1).
>         return value.match(/^[a-zA-Z][0-9][a-zA-Z](-| )?[0-9][a-zA-Z]
> [0-9]$/);
>
> }, 'Please enter a valid postal code');
>
> You can then use the rule postalCode:true to validate.

Reply via email to