Skip to content

Commit bd82337

Browse files
committed
Fixed outcode
1 parent 9e82908 commit bd82337

3 files changed

Lines changed: 9 additions & 2 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
var validationRegex = /^[a-z0-9]{1,4}\s*?\d[a-z]{2}$/i,
44
incodeRegex = /\d[a-z]{2}$/i,
5-
validOutcodeRegex = /[a-z0-9]{1,4}/i;
5+
validOutcodeRegex = /^[a-z0-9]{1,4}$/i;
66

77
function isValidPostcode (postcode) {
88
return !!postcode.match(validationRegex);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "postcode",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "UK Postcode helper methods",
55
"main": "index.js",
66
"directories": {

tests/unit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ describe("Postcode.validOutcode", function () {
5252
done();
5353
});
5454
});
55+
it ("should return false for invalid outcode", function (done) {
56+
var invalidOutcodes = ["BOGUS", "Hello there", "12345"];
57+
invalidOutcodes.forEach(function (code) {
58+
assert.isFalse(Postcode.validOutcode(code));
59+
});
60+
done();
61+
});
5562
});
5663

5764
describe("Incode parsing", function () {

0 commit comments

Comments
 (0)