Skip to content

Commit

Permalink
Only numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
condef5 committed Oct 5, 2018
1 parent 478ae87 commit 56321f6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>Opamp Designer</h1>
<h2>Try it Out</h2>
<p>Write the coefficients of all the terms in the equation with a space</p>
<div class="wrap-actions">
<input type="text" placeholder="Write coefficient" id="input">
<input type="text" onkeypress='validate(event)' placeholder="Write coefficient" id="input">
<a href="./designer.html">
<button class="go" onclick="localStorage.setItem('query',document.getElementById('input').value);">
Generate Circuit
Expand Down Expand Up @@ -66,4 +66,21 @@ <h2>What does this Opamp designer do?
<!-- <script src="js/canvasApi.js"></script>
<script src="js/renderer.js"></script> -->
<!-- <script src="js/renderer.js"></script> -->
<script>
function validate(evt) {
const theEvent = evt || window.event;

if (theEvent.type === 'paste') {
key = event.clipboardData.getData('text/plain');
} else {
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
}
var regex = /[0-9]|\./;
if( !regex.test(key) ) {
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
</script>
</html>

0 comments on commit 56321f6

Please sign in to comment.