Validate a textbox to accept numbers thats between 0 to 100 only
I have a textbox labeled "score". I want the user to enter a value between
0 and 100. How can I validate the value provided by the user?
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>
What I tried so far:
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;
}
No comments:
Post a Comment