@@ -4,6 +4,7 @@ var validationRegex = /^[a-z0-9]{1,4}\s*?\d[a-z]{2}$/i,
44 incodeRegex = / \d [ a - z ] { 2 } $ / i,
55 validOutcodeRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } $ / i,
66 areaRegex = / ^ [ a - z ] { 1 , 2 } / i,
7+ districtSplitRegex = / ^ ( [ a - z ] { 1 , 2 } \d ) ( [ a - z ] ) $ / i,
78 sectorRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } \s * ?\d / i,
89 unitRegex = / [ a - z ] { 2 } $ / i;
910
@@ -69,6 +70,24 @@ Postcode.prototype.area = function () {
6970 return this . _area ;
7071}
7172
73+ Postcode . prototype . district = function ( ) {
74+ if ( ! this . _valid ) return null ;
75+ if ( this . _district ) return this . _district ;
76+ var outcode = this . outcode ( ) ;
77+ var split = outcode . match ( districtSplitRegex ) ;
78+ this . _district = split ? split [ 1 ] : outcode ;
79+ return this . _district ;
80+ }
81+
82+ Postcode . prototype . subDistrict = function ( ) {
83+ if ( ! this . _valid ) return null ;
84+ if ( this . _subDistrict ) return this . _subDistrict ;
85+ var outcode = this . outcode ( ) ;
86+ var split = outcode . match ( districtSplitRegex ) ;
87+ this . _subDistrict = split ? outcode : null ;
88+ return this . _subDistrict ;
89+ }
90+
7291Postcode . prototype . sector = function ( ) {
7392 if ( ! this . _valid ) return null ;
7493 if ( this . _sector ) return this . _sector ;
0 commit comments