Last active
January 15, 2016 18:44
-
-
Save papayasoft/df030b5d6dd2d874c696 to your computer and use it in GitHub Desktop.
regex for pattern 00501 - 99999
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myTest = { | |
// Attempted test for pattern accepting anything 00501 - 999999 | |
pattern: /^(0050[1-9]|005[1-9][0-9]|00[6-9][0-9]{2}|0[1-9]{4}|[1-9][0-9]{4})$/, | |
// Some sample good string | |
good: ['00501', '00502', '00509', '00590', '00599', '00600', '00699', '09999', '12345', '54321'], | |
// Some sample bad strings | |
bad: ['', '0', '12', '300', '900', '5555', '00500', '00499', '00500'], | |
// A test that echoes on a bad string | |
echoOnFail: function(x) { | |
if (!this.pattern.test(x)) { | |
console.log('Unexpected fail: ', x); | |
} | |
}, | |
// a test that echoes on a good string | |
echoOnPass: function(x) { | |
if (this.pattern.test(x)) { | |
console.log('Unexpected pass: ', x); | |
} | |
}, | |
test: function() { | |
this.good.forEach(this.echoOnFail.bind(this)); | |
this.bad.forEach(this.echoOnPass.bind(this)); | |
} | |
}; | |
myTest.test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment