2013-08-09 9 views
2

텍스트 상자는 바코드 스캐너의 입력 만 허용하고 키보드의 다른 입력은 제한합니다.바코드 스캐너에서만 입력 가능한 텍스트 입력 허용 키보드의 입력을 제한합니다.

+0

가능한 중복

은 아래에있는 내 샘플 내가 ASP.NET을 사용하고

입니다 ] (http://stackoverflow.com/questions/14606005/bar-code-scanner-and-keyboard-issue) –

+0

키 누르기 이벤트 –

+0

@ Harsha, misguide 미안해의 기본 동작을 방지하려고합니다. 이것은 나의 질문이다. 나는 어떻게 기능을 달성 할 것인가? – user2450398

답변

2

다음

textBox.onkeypress = function(e) { 
     e = e || window.event; 
     var charCode = (typeof e.which == "number") ? e.which : e.keyCode; 
     if (/\D/.test(String.fromCharCode(charCode))) { 
      return false; 
     } 
    }; 
영숫자를 들어

LIVE DEMO

.. 그냥 바코드 스캐너를 연결을 시도하고 작동하는지 확인 .. 키보드 입력을 제한하는이

Chk 장치입니다 LIVE DEMO

+0

작동하지 않습니다. – user2450398

+0

영숫자를 허용하고 싶습니까? 나는 말해야한다 : e.which == "영숫자"?? – Kentot

+0

@Kentot 나는 알파벳순으로 답을 iupdated했습니다 –

0

체크 아웃 http://www.deadosaurus.com/detect-a-usb-barcode-scanner-with-javascript

링크에서 바코드 스캐너에서 입력하지 않은 10 자 길이 기준을 충족하지 못하는 것으로 가정 할 수있는 10 자 길이 기준을 충족하지 않을 때 텍스트를 자동으로 지우도록 수정했습니다.

ASP 코드 : 자바 스크립트를

<asp:TextBox ID="TextBoxComponentPartNumber" runat="server" onkeypress="AutoClearOrSetInputText(event,this.id);" ></asp:TextBox> 
     <asp:TextBox ID="TextBoxAssemblyPartNumber" runat="server" onkeypress="AutoClearOrSetInputText(event,this.id);" ></asp:TextBox> 

: [바코드 스캐너 및 키보드 문제의

<script type="text/javascript"> 

//This variables is for AutoClearOrSetInputText function 
var pressed = false; 
var chars = []; 

//This function will auto clear or set input text box’s text value 
function AutoClearOrSetInputText(eventForTextBox,idForTextBox) { 

// add each entered char to the chars array 
chars.push(String.fromCharCode(eventForTextBox.which)); 

// variable to ensure we wait to check the input we are receiving 
if (pressed == false) { 
// we set a timeout function that expires after 0.5 sec, once it does it clears out a list 
// of characters 
setTimeout(function() { 
// check we have a long length e.g. it is a barcode 
if (chars.length >= 10) { 
// join the chars array to make a string of the barcode scanned 
var barcode = chars.join(“”); 
// assign value to input for barcode scanner scanned value 
document.getElementById(idForTextBox).value = barcode; 
} 
else { 
// clear value from input for non-barcode scanner scanned value 
document.getElementById(idForTextBox).value = ”; 
} 
chars = []; 
pressed = false; 
}, 500); 
} 
// set press to true so we do not reenter the timeout function above 
pressed = true; 
} 
</script> 
관련 문제