0

I'm having a bit of a problem here. I'm using a JavaScript Library to filter inputs for a inputField. It works fine so far, only the allowed charackters are entered. But if the User presses AltGr (right alt || CTRL+ALT) he is still able to enter special charackters like @,€,[ and so on. Is there any way to restrict this? I tried the event.preventDefault(); way on doing this with keydown(); but it didn't work...

Here's the tiny snippet I'm using for my input filter:

$(".field").filter_input({ regex: '[a-zA-Z0-9]' });

This is the link to the jQ-Plugin I'm using: http://www.thimbleopensource.com/tutorials-snippets/jquery-plugin-filter-text-input

RenokK
  • 700
  • 8
  • 24

2 Answers2

1

Line 37 of the library (http://www.thimbleopensource.com/download/jquery/jquery.filter_input.js) returns and doesn't do any filtering if you're pressing CTRL or ALT.

if (event.ctrlKey || event.altKey) return;

Your options are:

  1. Try the solution @Sukanya posted (this doesn't exactly do what you're looking for I don't think) and/or write your own. See for hints: Jquery: filter input on keypress
  2. Pick a different library
  3. Download a copy of the library and delete line 37
Community
  • 1
  • 1
wholevinski
  • 3,658
  • 17
  • 23
0

Try this

<input id="txt" type="text" />

<script>
$("input:text").blur(function () {
                checkSpecialChar();
            });
            function checkSpecialChar()
            {
                var checkString = $("#txt").val();                
                if (checkString != "") {
                    if (/[^A-Za-z\d]/.test(checkString)) {
                        alert("Please enter only letter and numeric characters");                        
                        return (false);
                    }
                }
            }
</script>
Sukanya1991
  • 778
  • 3
  • 17