Skip to content

Commit 9e212a0

Browse files
committed
Merge pull request #5 from billinghamj/improved-regexes
Improved regexes
2 parents e94aba0 + b09c022 commit 9e212a0

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"use strict";
22

3-
var validationRegex = /^[a-z0-9]{1,4}\s*?\d[a-z]{2}$/i,
3+
var validationRegex = /^[a-z][a-z\d]{1,3}\s*?\d[a-z]{2}$/i,
44
incodeRegex = /\d[a-z]{2}$/i,
5-
validOutcodeRegex = /^[a-z0-9]{1,4}$/i,
5+
validOutcodeRegex = /^[a-z][a-z\d]{1,3}$/i,
66
areaRegex = /^[a-z]{1,2}/i,
77
districtSplitRegex = /^([a-z]{1,2}\d)([a-z])$/i,
8-
sectorRegex = /^[a-z0-9]{1,4}\s*?\d/i,
8+
sectorRegex = /^[a-z][a-z\d]{1,3}\s*?\d/i,
99
unitRegex = /[a-z]{2}$/i;
1010

1111
function isValidPostcode (postcode) {

tests/data/validation.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
"base" : "12FSSD",
2929
"expected" : false
3030
},
31+
{
32+
"base" : "1A1 1AA",
33+
"expected" : false
34+
},
35+
{
36+
"base" : "MA1 1AA",
37+
"expected" : true
38+
},
3139
{
3240
"base" : "BT35 8GE",
3341
"expected" : true

0 commit comments

Comments
 (0)