Skip to content

Instantly share code, notes, and snippets.

@niktariy
Last active July 10, 2019 11:55
Show Gist options
  • Save niktariy/d9980599c051a06a776a0ca7f19f9b5e to your computer and use it in GitHub Desktop.
Save niktariy/d9980599c051a06a776a0ca7f19f9b5e to your computer and use it in GitHub Desktop.
Input number with in- / out-of-range validation
/* CSS */
.input-field:valid {
border-color: lightgreen;
background-color: rgba(lightgreen, 0.1);
}
.input-field:valid ~ .msg-validation::before {
display: none;
}
.input-field:invalid {
border-color: red;
background-color: rgba(red, 0.1);
}
.input-field:out-of-range + .msg-validation::before {
content: 'Неверное значение';
}
<!-- HTML -->
<div class="form-group">
<label class="input-label" for="in-range">In-range input</label>
<input class="input-field" type="number" id="in-range"
min="1" max="10" value="8" required>
<span class="msg-validation range"> ( введите значение между 1 и 10 )</span>
</div>
<div class="form-group">
<label class="input-label" for="out-of-range">Out-of-range input</label>
<input class="input-field" type="number" id="out-of-range"
min="1" max="10" value="12" required>
<span class="msg-validation range"> ( введите значение между 1 и 10 )</span>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment