需要帮助使用 JavaScript 设置最小字符数
Need help setting a minimum number of characters using JavaScript
我正在尝试为密码字段设置至少 5 个字符,但它不起作用。每次我输入 0 或 1 个字符时它都可以工作,但在输入 2 到 5 个字符时挑战不起作用。有人可以看看我有什么并告诉我哪里出错了?
<fieldset>
<legend>Password</legend>
<label>Create Password</label>
<input type="password" name="password" id"password"><br /><br />
<label>Confirm Password</label>
<input type="password" name="confirmPassword" id="confirmPassword">
</fieldset><br />
if (document.sample.password.value <=5) {
alert("Password must contain 5 characters.");
document.sample.password.select();
document.sample.password.style.backgroundColor="yellow";
return true; // leave now
}
将其更改为:
<fieldset>
<legend>Password</legend>
<label>Create Password</label>
<input type="password" name="password" id="password"><br /><br />
<label>Confirm Password</label>
<input type="password" name="confirmPassword" id="confirmPassword">
</fieldset><br />
if (document.getElementById('password').length<=5) {
alert("Password must contain 5 characters.");
document.getElementById('password').select();
document.getElementById('password').style.backgroundColor="yellow";
return true; // leave now
}
请注意 HTML 中添加的=
,以便id"password"
相关文章:
- 使用正则表达式将输入格式设置为单字符逗号、单字符逗号等
- Rails 4 - 设置文本区域的字符数限制
- 如何使用javascript获取&使用字符偏移量设置插入符号位置
- 使用jquery为html元素文本的每个字符设置动画
- 打破ng中的字符数组,重复并设置每个字符自己的输入标记
- 如何指定输入元素中允许的最大字符数 - 设置 maxlength 属性是否足够
- 如何在文本框点击事件中设置文本框中字符的第一个位置---Chrome问题
- Firebase REST API - 如何设置字符编码
- 在输入框中设置“最小”字符输入抛出 javascript
- 需要帮助使用 JavaScript 设置最小字符数
- 将滑块输入值设置为闪亮字符
- 如何设置文本框的格式和允许的字符
- 如何为同一输入框中的字符设置不同的字体粗细
- 如何在不拆分单词的情况下将字符限制设置为100
- 使用非法字符设置DIV ID名称
- 如何在javascript中使用UTF-8字符设置Safari浏览器标题
- 我们可以对通过CKeditor输入的字符设置一个限制吗?
- 如何基于前三个字符设置元素样式
- 检测元素的innerHTML的最后一个字符是否为"1",如果是,下划线并将最后一个字符设置为绿色,并
- 如何为控制字符设置按键陷阱