<!DOCTYPE html>
<html>
  <head>
    <title>Input Angka - bayusapp.com</title>
  </head>
  <body>
    <h4>Using Tag HTML</h4>
    <form>
      <input type="number" name="angka" placeholder="Input Number">
      <button type="submit">Submit</button>
    </form>
    <h4>Using Pattern</h4>
    <form>
      <input type="text" name="angka" pattern="[0-9]" placeholder="Input Number">
      <button type="submit">Submit</button>
    </form>
    <h4>Using JavaScript</h4>
    <form>
      <input type="text" name="angka" placeholder="Input Number" onkeypress="return hanyaAngka(event)">
      <button type="submit">Submit</button>
    </form>
  </body>
</html>
function hanyaAngka(event) {
        var angka = (event.which) ? event.which : event.keyCode
        if (angka != 46 && angka > 31 && (angka < 48 || angka > 57))
          return false;
        return true;
      }

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.