Skip to content

Latest commit

 

History

History
39 lines (27 loc) · 741 Bytes

js_filter_chars.md

File metadata and controls

39 lines (27 loc) · 741 Bytes

JavaScript Filter Character

Filter and replace defined characters from inputs.

Installation

  • copy js_filter_chars.js to app/assets/javascripts/filter_chars.js

Usage

filterChars(); has this parameters:

  • chars — Regex, default /[~*?$§%°<>#!+,:;_&\/\\@()\[\]{}|"]/g
  • replacement — String, default: ''
$(function() {
    $("#firstname, #lastname, #zipcode, #city, #street").keyup( function() {
        $(this).filterChars();
    });
});

Example

Task: Replace any digits with 'x'

$(function() {
    $("#name").keyup( function() {
        $(this).filterChars({ chars: /\d/g, replacement: 'x' });
    });
});

Documentation