123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /**
- * @description 是否外链
- * @param {String} path
- * @returns {Boolean}
- */
- export function isExternal(path) {
- return /^(https?:|mailto:|tel:)/.test(path);
- }
- /**
- * @description 只允许输入两位小数
- * @param {String} value
- * @returns { Number }
- */
- export function twoDecimal(value) {
- if (!value) {
- return '';
- }
- let val = value;
- val = val.replace(/[^\d.]/g, ''); // 清除"数字"和"."以外的字符
- val = val.replace(/\.{2,}/g, '.'); // 只保留第一个 "." 清除多余的
- val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.');
- val = val.replace(/^(-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两位小数
- return val;
- }
- /**
- * @description 是否是数字
- * @param {String|Number} value
- * @returns {Boolean}
- */
- export function isNumber(value) {
- let _val = Number(value);
- if (typeof _val === 'number') {
- // 检查是否是有限数并且不是NaN
- return isFinite(_val) && !isNaN(_val);
- }
- return false;
- }
- /**
- * 判断 Node 元素类型
- * @param {Node} node
- * @param {String} type
- */
- export function isNodeType(node, type) {
- return node.nodeName.toLowerCase() === type.toLowerCase();
- }
|