File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11"use strict" ;
22
33var validationRegex = / ^ [ a - z 0 - 9 ] { 1 , 4 } \s * ?\d [ a - z ] { 2 } $ / i,
4- incodeRegex = / \d [ a - z ] { 2 } $ / i;
4+ incodeRegex = / \d [ a - z ] { 2 } $ / i,
5+ validOutcodeRegex = / [ a - z 0 - 9 ] { 1 , 4 } / i;
56
67function isValidPostcode ( postcode ) {
78 return ! ! postcode . match ( validationRegex ) ;
@@ -24,6 +25,10 @@ function Postcode (rawPostcode) {
2425 }
2526}
2627
28+ Postcode . validOutcode = function ( outcode ) {
29+ return ! ! outcode . match ( validationRegex ) ;
30+ }
31+
2732Postcode . prototype . valid = function ( ) {
2833 return this . _valid ;
2934}
Original file line number Diff line number Diff line change @@ -41,6 +41,29 @@ describe("Postcode normalisation", function () {
4141 } ) ;
4242} ) ;
4343
44+ describe ( "Postcode.validOutcode" , function ( ) {
45+ it ( "should return true for valid outcodes" , function ( done ) {
46+ testData = fs . readFile ( path . join ( dataDir , "outcodes.json" ) , function ( error , data ) {
47+ if ( error ) throw error ;
48+ testData = JSON . parse ( data ) ;
49+ testData . forEach ( function ( test ) {
50+ assert . isTrue ( Postcode . validOutcode ( test . expected ) ) ;
51+ } ) ;
52+ done ( ) ;
53+ } ) ;
54+ } ) ;
55+ it ( "should return false for invalid outcodes" , function ( done ) {
56+ testData = fs . readFile ( path . join ( dataDir , "incodes.json" ) , function ( error , data ) {
57+ if ( error ) throw error ;
58+ testData = JSON . parse ( data ) ;
59+ testData . forEach ( function ( test ) {
60+ assert . isFalse ( Postcode . validOutcode ( test . expected ) ) ;
61+ } ) ;
62+ done ( ) ;
63+ } ) ;
64+ } ) ;
65+ } )
66+
4467describe ( "Incode parsing" , function ( ) {
4568 before ( function ( done ) {
4669 testData = fs . readFile ( path . join ( dataDir , "incodes.json" ) , function ( error , data ) {
You can’t perform that action at this time.
0 commit comments