jamesthemullet
jamesthemullet

Reputation: 501

Jquery On Paste Not Working For Validating Input Field

I am trying to validate one form field, as the user types so that a message will be displayed if a certain domain extension is typed in the e-mail address.

Keeping the example simple so if the user types the letter 'j', it shows an alert, however if the user pastes the letter 'j', it does not.

I thought paste or propertychange would work but it is not working. I have had a good search through SO and not found any suggestions that worked.

Does anyone kindly have a suggestion?

$("#signup-Email").on( "keyup input propertychange paste", function(event) {
   setTimeout(function() {
      if(event.which == 74) 
         alert("Entered!");
   }, 50);
});

Upvotes: 0

Views: 2825

Answers (1)

jamesthemullet
jamesthemullet

Reputation: 501

Thanks to @AlivetoDie, for pointing me in the correct direction - the base for my answer was in

jQuery function bind on 'input propertychange' not firing as expected.

The following code took care of my requirements:

var text = "j";
$("#signup-Email").bind('input propertychange', function(){
    var value = $(this).val();
    if (value === text) {
        alert ("don't even think about it");
    }
});

Upvotes: 2

Related Questions