Daveo
Daveo

Reputation: 19872

jQuery use .live with jquery-keyfilter plugin

I am using jquery-keyfilter plugin to mask textbox inputs. However the textboxes are added to the page dynamically and I cannot figure out how to apply the key filter to them.

I have tried

$('#myelement').live('keyfilter', myFunction );

Also

$('#myelement').live('keyfilter', /regex/);

Kai: comment helps, but it seems my problem is still not solved

I want a keyfilter like this

(/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/);

that will only accept currency/money values but it seems like jquery-keyfilter does not work with this regex. Is this something I am doing wrong or should I look at using another plugin or just code it myself?

Upvotes: 0

Views: 767

Answers (2)

fuss
fuss

Reputation: 1

Below solution works for non-first character

  
$("#myelement").live("keypress", function(){  
  $(this).keyfilter((/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/);  
});

Below solution works for input field already clicked

  
$("#myelement").live("click", function(){    
  $(this).keyfilter((/^\$?(\d{1,3},?(\d{3},?)*\d{3}(.\d{0,3})?|\d{1,3}(.\d{2})?)$/);  
});  

Upvotes: 0

Kai
Kai

Reputation: 2987

"keyfilter" is not an event and you can NOT use live().
According to API of the plugin, it should be

$('#myelement').keyfilter(function(c) { return c != 'a'; }); 

$('#myelement').keyfilter(/[\dA-F]/); 

Upvotes: 3

Related Questions