MCPcopy Index your code
hub / github.com/validatorjs/validator.js / isFloat

Function isFloat

src/lib/isFloat.js:5–18  ·  view source on GitHub ↗
(str, options)

Source from the content-addressed store, hash-verified

3import { decimal } from './alpha';
4
5export default function isFloat(str, options) {
6 assertString(str);
7 options = options || {};
8 const float = new RegExp(`^(?:[-+])?(?:[0-9]+)?(?:\\${options.locale ? decimal[options.locale] : '.'}[0-9]*)?(?:[eE][\\+\\-]?(?:[0-9]+))?$`);
9 if (str === '' || str === '.' || str === ',' || str === '-' || str === '+') {
10 return false;
11 }
12 const value = parseFloat(str.replace(',', '.'));
13 return float.test(str) &&
14 (!options.hasOwnProperty('min') || isNullOrUndefined(options.min) || value >= options.min) &&
15 (!options.hasOwnProperty('max') || isNullOrUndefined(options.max) || value <= options.max) &&
16 (!options.hasOwnProperty('lt') || isNullOrUndefined(options.lt) || value < options.lt) &&
17 (!options.hasOwnProperty('gt') || isNullOrUndefined(options.gt) || value > options.gt);
18}
19
20export const locales = Object.keys(decimal);

Callers 1

toFloatFunction · 0.85

Calls 2

assertStringFunction · 0.85
isNullOrUndefinedFunction · 0.85

Tested by

no test coverage detected