Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<input type="number" id="input"/>
</body>
</html>
 
const input = document.querySelector('#input');
const format = /-?\d{0,5}(\.\d{0,2})?/;
let lastValue;
input.addEventListener('input', event => {
  document.execCommand('selectAll');
  let text = document.getSelection().toString();
  if (text !== lastValue) {
    const match = text.match(format);
    if (!match) {
      text = '';
    }
    else {
      text = match[0]
        .replace(/^(-?)0+(\d)/, '$1$2')
        .replace(/^(-?)\./, '$10.');
    }
    lastValue = text;
    document.execCommand('insertText', false, text);
  }
});
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers