Skip to content

Commit

Permalink
Merge branch 'master' into fix-creditcard-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso authored Jun 22, 2017
2 parents 718321f + fe79e6a commit bddc550
Show file tree
Hide file tree
Showing 15 changed files with 3,340 additions and 7 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#### HEAD

- Added an `isISRC()` validator for [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code)
([#660](https://github.com/chriso/validator.js/pull/660))
- New locales
([#647](https://github.com/chriso/validator.js/pull/647))
([#647](https://github.com/chriso/validator.js/pull/647),
[#667](https://github.com/chriso/validator.js/pull/667),
[#667](https://github.com/chriso/validator.js/pull/667),
[#671](https://github.com/chriso/validator.js/pull/671))

#### 7.0.0

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ Passing anything other than a string is an error.
- **isISSN(str [, options])** - check if the string is an [ISSN](https://en.wikipedia.org/wiki/International_Standard_Serial_Number). `options` is an object which defaults to `{ case_sensitive: false, require_hyphen: false }`. If `case_sensitive` is true, ISSNs with a lowercase `'x'` as the check digit are rejected.
- **isISIN(str)** - check if the string is an [ISIN][ISIN] (stock/security identifier).
- **isISO8601(str)** - check if the string is a valid [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) date.
- **isISRC(str)** - check if the string is a [ISRC](https://en.wikipedia.org/wiki/International_Standard_Recording_Code).
- **isIn(str, values)** - check if the string is in a array of allowed values.
- **isInt(str [, options])** - check if the string is an integer. `options` is an object which can contain the keys `min` and/or `max` to check the integer is within boundaries (e.g. `{ min: 10, max: 99 }`). `options` can also contain the key `allow_leading_zeroes`, which when set to false will disallow integer values with leading zeroes (e.g. `{ allow_leading_zeroes: false }`). Finally, `options` can contain the keys `gt` and/or `lt` which will enforce integers being greater than or less than, respectively, the value provided (e.g. `{gt: 1, lt: 4}` for a number between 1 and 4).
- **isJSON(str)** - check if the string is valid JSON (note: uses JSON.parse).
- **isLength(str, options)** - check if the string's length falls in a range. `options` is an object which defaults to `{min:0, max: undefined}`. Note: this function takes into account surrogate pairs.
- **isLowercase(str)** - check if the string is lowercase.
- **isMACAddress(str)** - check if the string is a MAC address.
- **isMD5(str)** - check if the string is a MD5 hash.
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']`).
- **isMobilePhone(str, locale)** - check if the string is a mobile phone number, (locale is one of `['ar-DZ', 'ar-SA', 'ar-SY', 'cs-CZ', 'de-DE', 'da-DK', 'el-GR', 'en-AU', 'en-GB', 'en-HK', 'en-IN', 'en-NG', 'en-NZ', 'en-US', 'en-CA', 'en-ZA', 'en-ZM', 'es-ES', 'en-PK', 'fa-IR', 'fi-FI', 'fr-FR', 'he-IL', 'hu-HU', 'it-IT', 'ja-JP', 'ko-KR', 'lt-LT', 'ms-MY', 'nb-NO', 'nn-NO', 'pl-PL', 'pt-PT', 'ro-RO', 'ru-RU', 'sr-RS', 'tr-TR', 'vi-VN', 'zh-CN', 'zh-HK', 'zh-TW']`).
- **isMongoId(str)** - check if the string is a valid hex-encoded representation of a [MongoDB ObjectId][mongoid].
- **isMultibyte(str)** - check if the string contains one or more multibyte chars.
- **isNumeric(str)** - check if the string contains only numbers.
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ var _isHexColor = require('./lib/isHexColor');

var _isHexColor2 = _interopRequireDefault(_isHexColor);

var _isISRC = require('./lib/isISRC');

var _isISRC2 = _interopRequireDefault(_isISRC);

var _isMD = require('./lib/isMD5');

var _isMD2 = _interopRequireDefault(_isMD);
Expand Down Expand Up @@ -280,6 +284,7 @@ var validator = {
isHexadecimal: _isHexadecimal2.default,
isDivisibleBy: _isDivisibleBy2.default,
isHexColor: _isHexColor2.default,
isISRC: _isISRC2.default,
isMD5: _isMD2.default,
isJSON: _isJSON2.default,
isEmpty: _isEmpty2.default,
Expand Down
21 changes: 21 additions & 0 deletions lib/isISRC.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = isISRC;

var _assertString = require('./util/assertString');

var _assertString2 = _interopRequireDefault(_assertString);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// see http://isrc.ifpi.org/en/isrc-standard/code-syntax
var isrc = /^[A-Z]{2}[0-9A-Z]{3}\d{2}\d{5}$/;

function isISRC(str) {
(0, _assertString2.default)(str);
return isrc.test(str);
}
module.exports = exports['default'];
3 changes: 3 additions & 0 deletions lib/isMobilePhone.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ var phones = {
'en-ZA': /^(\+?27|0)\d{9}$/,
'en-ZM': /^(\+?26)?09[567]\d{7}$/,
'es-ES': /^(\+?34)?(6\d{1}|7[1234])\d{7}$/,
'fa-IR': /^(\+?98[\-\s]?|0)9[0-39]\d[\-\s]?\d{3}[\-\s]?\d{4}$/,
'fi-FI': /^(\+?358|0)\s?(4(0|1|2|4|5)?|50)\s?(\d\s?){4,8}\d$/,
'fr-FR': /^(\+?33|0)[67]\d{8}$/,
'he-IL': /^(\+972|0)([23489]|5[0248]|77)[1-9]\d{6}/,
'hu-HU': /^(\+?36)(20|30|70)\d{7}$/,
'lt-LT': /^(\+370|8)\d{8}$/,
'id-ID': /^(\+?62|0[1-9])[\s|\d]+$/,
'it-IT': /^(\+?39)?\s?3\d{2} ?\d{6,7}$/,
'ko-KR': /^((\+?82)[ \-]?)?0?1([0|1|6|7|8|9]{1})[ \-]?\d{3,4}[ \-]?\d{4}$/,
'ja-JP': /^(\+?81|0)\d{1,4}[ \-]?\d{1,4}[ \-]?\d{4}$/,
'ms-MY': /^(\+?6?01){1}(([145]{1}(\-|\s)?\d{7,8})|([236789]{1}(\s|\-)?\d{7}))$/,
'nb-NO': /^(\+?47)?[49]\d{7}$/,
Expand Down
4 changes: 3 additions & 1 deletion lib/util/assertString.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ Object.defineProperty(exports, "__esModule", {
});
exports.default = assertString;
function assertString(input) {
if (typeof input !== 'string') {
var isString = typeof input === 'string' || input instanceof String;

if (!isString) {
throw new TypeError('This library (validator.js) validates strings only');
}
}
Expand Down
Loading

0 comments on commit bddc550

Please sign in to comment.