Actually, I want to validate the Canadian postal code form field using jQuery validation.
so i add the below method to validate Canadian postal code
//Canada zipcode validation methode
jQuery.validator.addMethod("canadazipRegex", function(value, element) {
return this.optional(element) || /^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$/i.test(value);
}, "<br>You must enter your postal code in this format: A#A #A#");
using this regular Expression
^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[
]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$
the field should allow only this format
A#A #A#
like :A1A 1A1
Not like:A1A1A1
So,How can i make sure white space after 3 characters.
I am not good with regular Expressions. if you give me good tutorial links also appreciated
Thanks in advance !
Don’t make the space optional :
Also there are no needs to use quantifier
{1}