|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么无论内容是什么都会检测为true?
- /**
- * 为指定id检测其内容是否为一定位数的符合[a-zA-Z0-9_]规则的内容。存在返回ture,不存在返回false。未找到指定id返回null并提示最近的两个id。
- * @param {any} idname - 指定的id名。默认为空
- * @param {any} minnumb - 最小位数,默认为0
- * @param {any} maxnumb - 最大位数,默认为6
- * @returns {boolean|null}
- */
- function alpcheck(idname = "", minnumb = 0, maxnumb = 6) {
- const idnames = document.getElementById(`${idname}`)
- if (idnames) {
- const rule = new RegExp(`^[a-zA-Z0-9_]{${minnumb},${maxnumb}}$`)
- prints(rule)
- if (rule.test(idnames.value) || rule.test(idnames.innerHTML)) {
- return true
- } else {
- return false
- }
- } else {
- checkid(idname)
- return null
- }
- }
复制代码
- /**
- * 为指定id检测其内容是否为一定位数的符合[a-zA-Z0-9_]规则的内容。存在返回true,不存在返回false。未找到指定id返回null并提示最近的两个id。
- * @param {string} idname - 指定的id名。默认为空
- * @param {number} minnumb - 最小位数,默认为0
- * @param {number} maxnumb - 最大位数,默认为6
- * @returns {boolean|null}
- */
- function alpcheck(idname = "", minnumb = 0, maxnumb = 6) {
- const idnames = document.getElementById(idname);
- if (idnames) {
- const rule = new RegExp(`^[a-zA-Z0-9_]{${minnumb},${maxnumb}}$`);
- const content = idnames.value || idnames.innerHTML; // Assuming that 'idnames' can be an input or other HTML element.
- return rule.test(content);
- } else {
- // checkid function needs to be defined or this call removed.
- // checkid(idname);
- console.log(`Element with id '${idname}' not found.`);
- return null;
- }
- }
复制代码
|
|