MCPcopy
hub / github.com/validatorjs/validator.js / isInt

Function isInt

src/lib/isInt.js:7–22  ·  view source on GitHub ↗
(str, options)

Source from the content-addressed store, hash-verified

5const intLeadingZeroes = /^[-+]?[0-9]+$/;
6
7export default function isInt(str, options) {
8 assertString(str);
9 options = options || {};
10
11 // Get the regex to use for testing, based on whether
12 // leading zeroes are allowed or not.
13 const regex = options.allow_leading_zeroes === false ? int : intLeadingZeroes;
14
15 // Check min/max/lt/gt
16 let minCheckPassed = (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || str >= options.min);
17 let maxCheckPassed = (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || str <= options.max);
18 let ltCheckPassed = (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || str < options.lt);
19 let gtCheckPassed = (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || str > options.gt);
20
21 return regex.test(str) && minCheckPassed && maxCheckPassed && ltCheckPassed && gtCheckPassed;
22}

Callers 2

isIdentityCard.jsFile · 0.85
isPortFunction · 0.85

Calls 2

assertStringFunction · 0.85
isNullOrUndefinedFunction · 0.85

Tested by

no test coverage detected