Skip to content

Commit

Permalink
issue gouri-panda#5 resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush-AI committed Oct 5, 2020
1 parent 57fff41 commit d37941b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 17 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@
<input type="text" class="add__description" placeholder="Add description">
</div>
<div class="add__field-container">
<input type="number" class="add__value" placeholder="Value" min="0">
<input type="number" class="add__value" placeholder="Value" min="0" onkeypress="return isNumber(event)">
<span class="add__error">This field is required</span>
<!-- Error message if non-numeric characters are entered. (modify it if u need) -->
<span class="error"> Enter numbers only</span>
</div>
<button class="add__btn"><i class="ion-ios-checkmark-outline"></i></button>
</div>
Expand Down Expand Up @@ -138,6 +140,20 @@ <h2 class="expenses__title">Expenses</h2>
time: '0.5s',
label: '🌓'
}).showWidget();

// event listener function for checking the non numeric input and throwing the error.
function isNumber(evt) {
var errorClass = document.querySelector('.error');
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
errorClass.style.display = 'block';
return false;
}
errorClass.style.display = 'none';
return true;
}

</script>

</body> /* Ending of body */
Expand Down
4 changes: 4 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ body {
text-align: left;
display: none;
}
.error{
display: none;
color: red;
}

.add__title,
.add__description,
Expand Down

0 comments on commit d37941b

Please sign in to comment.