Skip to content

Commit

Permalink
Updated regex and bumped version
Browse files Browse the repository at this point in the history
  • Loading branch information
Zenedith committed Jan 18, 2015
1 parent f426c99 commit 1bed497
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
15 changes: 8 additions & 7 deletions lib/polandPlateValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var prepareInput = function (input) {
return input.replace(/[\W\s]+/g, '');
};

var regex = function (reg) {
return /^[a-zA-Z]{3}[ -]?\d{2}[a-zA-Z]{2}$/.test(reg) ||
/^[a-zA-Z]{3}[ -]?[a-zA-Z0-9]{4,5}$/.test(reg) ||
/^[a-zA-Z]\d[ -]?[a-zA-Z0-9]{4,5}$/.test(reg);
};

module.exports.validate = function (input, callback) {
var reg = prepareInput(input);

Expand All @@ -22,9 +28,7 @@ module.exports.validate = function (input, callback) {
plateFormat: null
};

var valid = /^[a-zA-Z]{3}[ -]?\d{2}[a-zA-Z]{2}$/.test(reg) ||
/^[a-zA-Z]{3}[ -]?[a-zA-Z0-9]{4,5}$/.test(reg) ||
/^[a-zA-Z]\d[ -]?[a-zA-Z0-9]{4,5}$/.test(reg);
var valid = regex(reg);

if (!valid) {
err = 1;
Expand All @@ -35,8 +39,5 @@ module.exports.validate = function (input, callback) {

module.exports.isValid = function (input) {
var reg = prepareInput(input);

return /^[a-zA-Z]{3}[ -]?\d{2}[a-zA-Z]{2}$/.test(reg) ||
/^[a-zA-Z]{3}[ -]?[a-zA-Z0-9]{4}$/.test(reg) ||
/^[a-zA-Z]\d[ -]?[a-zA-Z0-9]{4,5}$/.test(reg);
return regex(reg);
};
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pl-numberplates",
"version": "0.5.1",
"version": "0.5.2",
"description": "Node JS package to validate PL number plates.",
"main": "./index.js",
"dependencies": {
Expand Down Expand Up @@ -44,6 +44,6 @@
"node": ">=0.10.0"
},
"readmeFilename": "README.md",
"_id": "pl-numberplates@0.5.1",
"_from": "pl-numberplates@^0.5.1"
"_id": "pl-numberplates@0.5.2",
"_from": "pl-numberplates@^0.5.2"
}
14 changes: 11 additions & 3 deletions test/polandPlateValidatorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,28 @@ describe('poland plate validator test', function () {
});

it('should validate plate in format AAA 11AA', function (done) {
var plate = 'pwr 17wq';
var plate = 'AAA 11AA';

polandPlateValidator.validate(plate, function (err, data) {
expect(err, plate + ' should be valid').is.false;
data.plate.should.equal('PWR17WQ');
data.plate.should.equal('AAA11AA');
done();
});
});

it('should check if plate is valid', function (done) {
it('should check if plate AAA 11AA is valid', function (done) {
var plate = 'pwr 17wq';

var result = polandPlateValidator.isValid(plate);
expect(result, plate + ' should be valid').is.true;
done();
});

it('should check if plate AAA 11111 is valid', function (done) {
var plate = 'AAA11111';

var result = polandPlateValidator.isValid(plate);
expect(result, plate + ' should be valid').is.true;
done();
});
});

0 comments on commit 1bed497

Please sign in to comment.