acdr-ui/dist/dev/mp-weixin/sheep/helper/test.js.map

1 line
8.8 KiB
Plaintext
Raw Normal View History

2024-09-19 07:20:14 +08:00
{"version":3,"file":"test.js","sources":["../../../../../src/sheep/helper/test.js"],"sourcesContent":["/**\r\n * 验证电子邮箱格式\r\n */\r\nfunction email(value) {\r\n return /^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$/.test(value)\r\n}\r\n\r\n/**\r\n * 验证手机格式\r\n */\r\nfunction mobile(value) {\r\n return /^1[23456789]\\d{9}$/.test(value)\r\n}\r\n\r\n/**\r\n * 验证URL格式\r\n */\r\nfunction url(value) {\r\n return /^((https|http|ftp|rtsp|mms):\\/\\/)(([0-9a-zA-Z_!~*'().&=+$%-]+: )?[0-9a-zA-Z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-zA-Z_!~*'()-]+.)*([0-9a-zA-Z][0-9a-zA-Z-]{0,61})?[0-9a-zA-Z].[a-zA-Z]{2,6})(:[0-9]{1,4})?((\\/?)|(\\/[0-9a-zA-Z_!~*'().;?:@&=+$,%#-]+)+\\/?)$/.test(\r\n value,\r\n )\r\n}\r\n\r\n/**\r\n * 验证日期格式\r\n */\r\nfunction date(value) {\r\n if (!value) return false\r\n // 判断是否数值或者字符串数值(意味着为时间戳)转为数值否则new Date无法识别字符串时间戳\r\n if (number(value)) value = +value\r\n return !/Invalid|NaN/.test(new Date(value).toString())\r\n}\r\n\r\n/**\r\n * 验证ISO类型的日期格式\r\n */\r\nfunction dateISO(value) {\r\n return /^\\d{4}[\\/\\-](0?[1-9]|1[012])[\\/\\-](0?[1-9]|[12][0-9]|3[01])$/.test(value)\r\n}\r\n\r\n/**\r\n * 验证十进制数字\r\n */\r\nfunction number(value) {\r\n return /^[\\+-]?(\\d+\\.?\\d*|\\.\\d+|\\d\\.\\d+e\\+\\d+)$/.test(value)\r\n}\r\n\r\n/**\r\n * 验证字符串\r\n */\r\nfunction string(value) {\r\n return typeof value === 'string'\r\n}\r\n\r\n/**\r\n * 验证整数\r\n */\r\nfunction digits(value) {\r\n return /^\\d+$/.test(value)\r\n}\r\n\r\n/**\r\n * 验证身份证号码\r\n */\r\nfunction idCard(value) {\r\n return /^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X)$/.test(value)\r\n}\r\n\r\n/**\r\n * 是否车牌号\r\n */\r\nfunction carNo(value) {\r\n // 新能源车牌\r\n const xreg =\r\n /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}(([0-9]{5}[DF]$)|([DF][A-HJ-NP-Z0-9][0-9]{4}$))/\r\n // 旧车牌\r\n const creg =\r\n /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳]{1}$/\r\n if (value.length === 7) {\r\n return creg.test(value)\r\n }\r\n if (value.length === 8) {\r\n return xreg.test(value)\r\n }\r\n return false\r\n}\r\n\r\n/**\r\n * 金额,只允许2位小数\r\n */\r\nfunction amount(value) {\r\n // 金额,只允许保留两位小数\r\n return /^[1-9]\\d*(,\\d{3})*(\\.\\d{1,2})?$|^0\\.\\d{1,2}$/.test(value)\r\n}\r\n\r\n/**\r\n * 中文\r\n */\r\nfunction chinese(value) {\r\n const reg = /^[\\u4e00-\\u9fa5]+$/gi\r\n return reg.test(value)\r\n}\r\n\r\n/**\r\n * 只能输入字母\r\n */\r\nfunction letter(value) {\r\n return /^[a-zA-Z]*$/.test(value)\r\n}\r\n\r\n/**\r\n * 只能是字母或者数字\r\n */\r\nfunction enOrNum(value) {\r\n // 英文或者数字\r\n const reg = /^[0-9a-zA-Z]*$/g\r\n return reg.test(value)\r\n}\r\n\r\n/**\r\n * 验证是否包含某个值\r\n */\r\nfunction contains(value, param) {\r\n return value.indexOf(param) >= 0\r\n}\r\n\r\n/**\r\n * 验证一个值范围[min, max]\r\n */\r\nfunction range(value, param) {\r\n return value >= param[0] && value <= param[1]\r\n}\r\n\r\n/**\r\n * 验证一个长度范围[min, max]\r\n */\r\nfunction rangeLength(value, param) {\r\n return value.length >= param[0] && value.length <= param[1]\r\n}\r\n\r\n/**\r\n * 是否固定电话\r\n */\r\nfunction landline(value) {\r\n const reg = /^\\d{3,4}-\\d{7,8}(-\\d{3,4})?$/\r\n return reg.test(value)\r\n}\r\n\r\n/**\r\n * 判断是否为空\r\n */\r\nfunction empty(value) {\r\n switch (typeof value) {\r\n case 'undefined':\r\n return true\r\n case 'string':\r\n if (value.replace(/(^[ \\t\\n\\r]*)|([ \\t\\n\\r]*$)/g, '').length == 0) return true\r\n break\r\n case 'boolean':\r\n if (!value) return true\r\n break\