กรองข้อมูลด้วย JQuery plugin for input text field filtering

55


This is simple JQuery plugin for filtering text input field by using regexp. Only allowed characters will be inserted into input field, others will be silently dropped.

Usage example

// only lowercase alphabets are allowed
$('#text_input').filter_input({regex:'[a-z]'}); 

// only numbers are allowed
$('#text_input').filter_input({regex:'[0-9]'}); 

// only URL safe characters are allowed
$('#text_input').filter_input({regex:'[a-zA-Z0-9_]'}); 

// use live() for binding to elements - from version 1.1.0
$('.input').filter_input({regex:'[a-z]', live:true}); 

// use callback function "feedback" when key test is negative - from version 1.3.0
$('.input').filter_input({
regex:'[a-z]',
feedback: function(char) {

// "this" contains a reference to the inputfield
alert('character ' + char + ' is not allowed in input ' + $(this).attr('id'));
}
}); 


// filter now supports also "paste" event, enabled by default - from version 1.4.2
$('.input').filter_input({
regex:'[a-z]',
events:'keypress paste'
});

Download