.dnkl_onlyAlphaNumeric()

.dnkl_onlyAlphaNumeric()

This jQuery plugin makes an input field only contain alphanumeric characters

jQuery.fn.dnkl_onlyAlphaNumeric = function() {
    /*
    NAME: 	dnkl_onlyAlphaNumeric()
    VERS:	1.0
    DESC:	Removes non-alpha/numeric characters from value
    USAGE:	$('#myInputID').dnkl_onlyAlphaNumeric();
    */
    return $(this).each(function() {
        $(this).keyup(function() {
            var reg = new RegExp('[^0-9A-z]');
            if ($(this).val().match(reg)) {
                $(this).val($(this).val().replace(/[^\-0-9A-z]/g, ''));
            }
        });
    });
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>