UNPKG

@mapbox/mr-ui

Version:

UI components for Mapbox projects

37 lines (36 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = validatePassword; var _react = _interopRequireDefault(require("react")); var _isEmptyControlValue = _interopRequireDefault(require("./is-empty-control-value")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function validatePassword(value) { if ((0, _isEmptyControlValue.default)(value)) return null; const validations = []; if (value.length < 8) { validations.push('Password must be at least eight characters long.'); } if (!/[a-z]/.test(value)) { validations.push('Password must have a lowercase letter.'); } if (!/[A-Z]/.test(value)) { validations.push('Password must have an uppercase letter.'); } if (!/\d/.test(value)) { validations.push('Password must have a number.'); } if (!/\W/.test(value)) { validations.push('Password must have a special character like ".!@#$%^&*()+-=,".'); } if (validations.length === 0) { return null; } return /*#__PURE__*/_react.default.createElement("ul", { className: "list-group" }, validations.map((listitem, i) => /*#__PURE__*/_react.default.createElement("li", { key: i, className: "list-group-item" }, listitem))); }