Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

QR CODE

let scanner = new Instascan.Scanner({
  video: document.getElementById('preview'),
  mirror: false
});

Instascan.Camera.getCameras().then(function(cameras) {
  if (cameras.length > 0) {
    scanner.start(cameras[0]);
  } else {
    console.error('No cameras found.');
    alert('No cameras found.');
  }
}).catch(function(e) {
  console.error(e);
  alert(e);
});


$(function() {
  const re = /(d+-d+)s+(.*)/;
  scanner.addListener('scan', function(content) {
    console.log(content);
    if (!re.test(content)) {
      console.log("malformed strings")
      return;
    }
    const [_, id, name] = content.match(re);
    $(".idnum").val(id);
    $(".idname").val(name.trim());
  });
})
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #QR #CODE
ADD COMMENT
Topic
Name
8+3 =