card-validator
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -0,1 +1,6 @@ | ||
4.1.0 | ||
===== | ||
- Add options object for postal code validation to specify min length | ||
4.0.0 | ||
@@ -2,0 +7,0 @@ ===== |
{ | ||
"name": "card-validator", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A library for validating credit card fields", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -278,3 +278,3 @@ # Credit Card Validator [![Build Status](https://travis-ci.org/braintree/card-validator.svg)](https://travis-ci.org/braintree/card-validator) [![npm version](https://badge.fury.io/js/card-validator.svg)](http://badge.fury.io/js/card-validator) | ||
#### `valid.postalCode(value: string): object` | ||
#### `valid.postalCode(value: string, [options: object]): object` | ||
@@ -290,2 +290,13 @@ The `postalCode` validation essentially tests for a valid string greater than 3 characters in length. | ||
You can optionally pass `minLength` as a property of an object as a second argument. This will override the default min length of 3. | ||
```javascript | ||
valid.postalCode('123', {minLength: 5}); | ||
{ | ||
isPotentiallyValid: true, | ||
isValid: false | ||
} | ||
``` | ||
## Design decisions | ||
@@ -292,0 +303,0 @@ |
'use strict'; | ||
var MIN_POSTAL_CODE_LENGTH = 3; | ||
var DEFAULT_MIN_POSTAL_CODE_LENGTH = 3; | ||
@@ -9,6 +9,12 @@ function verification(isValid, isPotentiallyValid) { | ||
function postalCode(value) { | ||
function postalCode(value, options) { | ||
var minLength; | ||
options = options || {}; | ||
minLength = options.minLength || DEFAULT_MIN_POSTAL_CODE_LENGTH; | ||
if (typeof value !== 'string') { | ||
return verification(false, false); | ||
} else if (value.length < MIN_POSTAL_CODE_LENGTH) { | ||
} else if (value.length < minLength) { | ||
return verification(false, true); | ||
@@ -15,0 +21,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22618
288
316