Close

Not a member yet? Register now and get started.

lock and key

Sign in to your account.

Account Login

Forgot your password?

限制欄位只允許輸入某些字元

限制欄位只允許輸入某些字元

  1. 利用 keypress 事件來監聽 user 輸入的字元。
  2. 允許使用後退鍵。
  3. 允許key入半型數字、半型逗號、dash 等字元。
程式碼:
1
2
3
4
5
6
7
8
9
10
<script type="text/javascript">
<!-- <![CDATA[
$(function() {
    $('#issueNumberRange').keypress(function(event) {
        if (8 == (window.event ? event.keyCode : event.which)) { return ture; }
        return /[0-9,-]/.test(String.fromCharCode((window.event ? event.keyCode : event.which)));
    });
});
// ]]> -->
</script>

 

Leave a Reply

*