diff --git a/README.md b/README.md index 86e7f4c57..532ae4b3a 100755 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ notIn(options) max(val) min(val) isCreditCard() //Will work against Visa, MasterCard, American Express, Discover, Diners Club, and JCB card numbering formats +isCanadaPostCode() //Accepts both spaced and non-spaced formats (e.g. H2G 1M1 & H2G1M1) ``` ## List of sanitization / filter methods diff --git a/lib/defaultError.js b/lib/defaultError.js index c5479049e..27bfb9030 100644 --- a/lib/defaultError.js +++ b/lib/defaultError.js @@ -30,6 +30,7 @@ var defaultError = module.exports = { min: 'Invalid number', max: 'Invalid number', isArray: 'Not an array', - isCreditCard: 'Invalid credit card' + isCreditCard: 'Invalid credit card', + isCanadaPostCode: 'Invalid Canada post code' }; diff --git a/lib/validators.js b/lib/validators.js index 61316a3ec..de1aeaf4c 100644 --- a/lib/validators.js +++ b/lib/validators.js @@ -231,5 +231,9 @@ var validators = module.exports = { } else { return null; } + }, + //Accepts both spaced and non-spaced formats (e.g. H2G 1M1 & H2G1M1) + isCanadaPostCode: function(str, options) { + return str.match(/^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/); } };