UNPKG

java-bean-validation.js

Version:
106 lines 3.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var core_1 = require("../core/core"); var MAX_INTEGER_VALUE = 2147483647; var MAX_LONG_VALUE = 9223372036854775807; var validator; core_1.VALIDATORS['Email'] = function EmailValidator(value) { if (value === null || value === undefined) { return true; } if (typeof value === 'number') { value = value + ''; } if (value instanceof Date) { value = value + ''; } if (typeof value !== 'string') { return true; } var emailregex = /^[a-z0-9!#$%&'*+\/=?^_`{|}~.-]+@[a-z0-9]([a-z0-9-]*[a-z0-9])?(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?)*$/i; return emailregex.test(value); }; validator = function LengthValidator(value, attributes) { if (value === null || value === undefined) { return true; } if (typeof value === 'number') { value = value + ''; } if (value instanceof Date) { value = value + ''; } if (typeof value !== 'string') { return true; } var min = attributes.min; var max = attributes.max; var length = value.length; return +min <= length && +max >= length; }; validator.defaultValues = { min: 0, max: MAX_INTEGER_VALUE }; core_1.VALIDATORS['Length'] = validator; validator = function NotBlankValidator(value) { if (value === null || value === undefined) { return false; } if (typeof value === 'string') { value = value.trim(); return value.length > 0; } if (typeof value === 'number') { return true; } if (value instanceof Date) { return true; } return true; }; validator.isHtmlRequiredValidator = true; core_1.VALIDATORS['NotBlank'] = validator; core_1.VALIDATORS['NotEmpty'] = function NotEmptyValidator(_value) { return true; }; validator = function RangeValidator(_value, _attributes) { return true; }; validator.defaultValues = { min: 0, max: MAX_LONG_VALUE }; core_1.VALIDATORS['Range'] = validator; validator = function URLValidator(value, attributes) { if (value === null || value === undefined) { return true; } if (typeof value === 'number') { value = value + ''; } if (value instanceof Date) { value = value + ''; } if (typeof value !== 'string') { return true; } var protocol = attributes.protocol; if (protocol === '') { protocol = URLValidator.defaultValues.protocol; } var host = attributes.host; if (host === '') { host = '(\\w+?:{0,1}\\w*?@)?(\\S+?)'; } var port; if (attributes.port === -1) { port = '(:[0-9]+?)?'; } else { port = ':' + attributes.port + ''; if (port === ':-1') { port = '(:[0-9]+?)?'; } } var urlregex = '^(' + protocol + '):\\/\\/' + host + port + '([\\w#!:.?+=&%@!\\-\\/])*$'; var regex = new RegExp(urlregex); return regex.test(value); }; validator.defaultValues = { protocol: 'ftp|http|https', host: '', port: -1 }; core_1.VALIDATORS['URL'] = validator; //# sourceMappingURL=hibernateValidators.js.map