tags:

views:

124

answers:

1

I try to use the jquery Alphanumeric plug-in http://itgroup.com.ph/alphanumeric/ and it works fine.The problem is when I paste this text !@#$%^&*()_67890-qwertyuiopasdfghjkl'zxcvbnm,. the textbox accepted it.

here is my code:

$("#<%=txtAddCompanyName.ClientID%>").alphanumeric({ allow: "'-., " });

I tried to changed my code to shown below but it was not working.

document.getElementById("<%=txtAddCompanyName.ClientID%>").onpaste = function() {
  $("#<%=txtAddCompanyName.ClientID%>").alphanumeric({ allow: "'-., " });
 }; 

Any ideas?

A: 

Update

look for this on alphanumeric.js

$(this).keypress
    (
        function (e)
            {

                if (!e.charCode) k = String.fromCharCode(e.which);
                    else k = String.fromCharCode(e.charCode);

                if (ch.indexOf(k) != -1) e.preventDefault();
                if (e.ctrlKey&&k=='v') e.preventDefault();

            }

    );

then change keypress to keydown at least this will prevent pasted values...

other than that, I have no other suggestion....


original answer

try any of this...

document.getElementById("<%=txtAddCompanyName.ClientID%>").onpaste = function() {
  $("#<%=txtAddCompanyName.ClientID%>").trigger('keypress');
 }; 

or

document.getElementById("<%=txtAddCompanyName.ClientID%>").onpaste = function() {
  $("#<%=txtAddCompanyName.ClientID%>").trigger('keydown');
 };

or

document.getElementById("<%=txtAddCompanyName.ClientID%>").onpaste = function() {
  $("#<%=txtAddCompanyName.ClientID%>").trigger('keyup');
 };
Reigel
not working....
please see update... :)
Reigel
I think this will not suppose to work.Anyway,thanks, i will add a new function to that alphanumeric plug-in.
For future reference you could do `$(this).trigger('keypress')` inside those, `this` has the meaning you want :)
Nick Craver
ahh thanks nick... I was thinking of that... I was just not sure... :)
Reigel
$(this).bind('paste', function() { return false }); $(this).bind('cut', function() { return false }); $(this).bind('copy', function() { return false }); for those who needed to avoid paste,cut, and copy add this on the alphanumeric plugin
you can post it as answer though... :)
Reigel