1
我有一個標有「得分」文本框。我希望用戶輸入介於0和100之間的值。我如何驗證用戶提供的值?驗證一個文本框接受0到100之間的數字,多數民衆贊成只
HTML:
<div class="editor-label"> Score </div>
<div class="editor-field">
<input type="text" name="Score" id="Score" maxlength="25" />
<span id="ScoreError" class="error"></span>
</div>
我試過到目前爲止:
var num = document.getElementById("Score").value;
if (num < 0 || num > 100){
document.getElementById("ScoreError").innerHTML = "- Score is required.";
alert("Enter a Score thats between 0 to 100")
isValidForm = false;
}
你爲什麼不使用'',_type_設置爲'number',_min_'0',_max_'100'和_value_'0'? http://jsfiddle.net/A7EFa/ –
看看[這裏](http://utilitymill.com/utility/Regex_For_Range) – BrOSs
請[編輯]你的問題,而不是在評論張貼代碼。這個條件對我來說確實很好。何時/如何運行代碼? –