键盘大小写提示是哪个键?
- 内容介绍
- 文章标签
- 相关推荐
本文共计348个文字,预计阅读时间需要2分钟。
使用JavaScript获取键盘的大小写,检测大写锁定键状态,并提示密码要求:
javascript// 获取键盘大小写状态function getKeyboardCase() { const isUpperCaseLock=navigator.platform.includes('Mac') ? (navigator.userAgent.match(/OS (\d+)_(\d+)_?(\d+)?/) ? parseInt(RegExp.$1, 10) >=10 : false) : (document.layers ? window.document.layers.keyState : window.keyState) & 0x04;
return isUpperCaseLock ? '大写锁定键已开启' : '大写锁定键未开启';}
// 检测密码要求function checkPassword(password) { const hasUpperCase=/[A-Z]/.test(password); const hasLowerCase=/[a-z]/.test(password); const hasNumber=/\d/.test(password); const hasSpecialChar=/[!@#$%^&*()_+\-=\[\]{};':\\|,.\/?]+/.test(password); const isValidLength=password.length >=8;
const message=[ hasUpperCase ? '' : '密码必须包含大写字母', hasLowerCase ? '' : '密码必须包含小写字母', hasNumber ? '' : '密码必须包含数字', hasSpecialChar ? '' : '密码必须包含特殊字符', isValidLength ? '' : '密码长度至少为8位' ].join(',');
return message || '密码符合要求';}
// 测试console.log(getKeyboardCase());console.log(checkPassword('Password123!'));
js 实现获取键盘的大小写
检测大写锁定键
本文共计348个文字,预计阅读时间需要2分钟。
使用JavaScript获取键盘的大小写,检测大写锁定键状态,并提示密码要求:
javascript// 获取键盘大小写状态function getKeyboardCase() { const isUpperCaseLock=navigator.platform.includes('Mac') ? (navigator.userAgent.match(/OS (\d+)_(\d+)_?(\d+)?/) ? parseInt(RegExp.$1, 10) >=10 : false) : (document.layers ? window.document.layers.keyState : window.keyState) & 0x04;
return isUpperCaseLock ? '大写锁定键已开启' : '大写锁定键未开启';}
// 检测密码要求function checkPassword(password) { const hasUpperCase=/[A-Z]/.test(password); const hasLowerCase=/[a-z]/.test(password); const hasNumber=/\d/.test(password); const hasSpecialChar=/[!@#$%^&*()_+\-=\[\]{};':\\|,.\/?]+/.test(password); const isValidLength=password.length >=8;
const message=[ hasUpperCase ? '' : '密码必须包含大写字母', hasLowerCase ? '' : '密码必须包含小写字母', hasNumber ? '' : '密码必须包含数字', hasSpecialChar ? '' : '密码必须包含特殊字符', isValidLength ? '' : '密码长度至少为8位' ].join(',');
return message || '密码符合要求';}
// 测试console.log(getKeyboardCase());console.log(checkPassword('Password123!'));
js 实现获取键盘的大小写

