Javascript – Detect Comma/Enter key press


There are some comma separated values in an input field. I want to alert a message when I am pressing the COMMA(,) or ENTER key. I have given the code that I used for this, but didn't work. Is there anything inefficient about this?

$(document).on("keyup", '.tagsinput', function (e) {
    if (e.which == 13 || e.which == 44) {
        alert('comma added');

Best Solution

The keycode (which in jQuery) for a comma is 188

There is a brilliant tool for this here