Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement isPassportNumber Validator #1250

Merged

Conversation

hamzahejja
Copy link
Contributor

@hamzahejja hamzahejja commented Feb 16, 2020

  • Per issue Validator for passport numbers #1218 , This PR introduces an implementation to: isPassportNumber(str, countryCode) validator, which validates the input string against a passport no. regex that corresponds to the passed-in ISO country code 🎉

References:

@hamzahejja
Copy link
Contributor Author

hamzahejja commented Feb 16, 2020

@profnandaa Have a look at it when you're free to 👍

@hamzahejja
Copy link
Contributor Author

@dani2819 Abdullah -- FYI ☝️

Copy link
Member

@profnandaa profnandaa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work on this Hamza, thanks! Few comments:

  • add a few test cases
  • remove the stray code indicated

validator.js Outdated
@@ -402,7 +402,7 @@ function isFQDN(str, options) {
to the 5th link, and "interface10" belongs to the 10th organization.
* * */

var ipv4Maybe = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
var ipv4Maybe = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this unrelated change.

validator.js Outdated
@@ -848,6 +848,17 @@ function isBoolean(str) {
return ['true', 'false', '1', '0'].indexOf(str) >= 0;
}

var localeReg = /^[A-z]{2,4}([_-]([A-z]{4}|[\d]{3}))?([_-]([A-z]{2}|[\d]{3}))?$/;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this too.

@@ -2420,6 +2524,7 @@ var validator = {
isJSON: isJSON,
isEmpty: isEmpty,
isLength: isLength,
isLocale: isLocale,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa Should this be removed as well ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please -- all the unrelated diff.

@@ -35,12 +35,16 @@ var _isFQDN = _interopRequireDefault(require("./lib/isFQDN"));

var _isBoolean = _interopRequireDefault(require("./lib/isBoolean"));

var _isLocale = _interopRequireDefault(require("./lib/isLocale"));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa Remove this ?

@@ -227,6 +232,7 @@ var validator = {
isJSON: _isJSON.default,
isEmpty: _isEmpty.default,
isLength: _isLength.default,
isLocale: _isLocale.default,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa Should be removed ?

@@ -1853,6 +1853,522 @@ describe('Validators', () => {
});
});

it('should validate passport number', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa Check here for the tests, I've already included test-cases, one per country code. It's a Large diff, it had be manually loaded, probably that's why you didn't notice it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad missed that.

@tux-tn
Copy link
Member

tux-tn commented Feb 17, 2020

Great job @hamzahejja 🎉

@@ -1853,6 +1853,522 @@ describe('Validators', () => {
});
});

it('should validate passport number', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad missed that.

@profnandaa profnandaa merged commit 9836c29 into validatorjs:master Feb 17, 2020
@hamzahejja hamzahejja deleted the add-isPassportNumber-validator branch February 17, 2020 19:06
@@ -140,6 +140,7 @@ Validator | Description
**isMultibyte(str)** | check if the string contains one or more multibyte chars.
**isNumeric(str [, options])** | check if the string contains only numbers.<br/><br/>`options` is an object which defaults to `{no_symbols: false}`. If `no_symbols` is true, the validator will reject numeric strings that feature a symbol (e.g. `+`, `-`, or `.`).
**isOctal(str)** | check if the string is a valid octal number.
**isPassportNumber(str, countryCode) | check if the string is a valid passport number relative to a specific country code.
Copy link
Contributor Author

@hamzahejja hamzahejja Feb 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@profnandaa Could you just update README.md at master branch and change/fix this line to the correct styling, i.e.
**isPassportNumber(str, countryCode)**

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, will do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants