This code restrict pasting of other characters apart from numbers in the input field.On pasting a value to an input field, I'm testing the value with the regex, if the condition is true, the value will be set, or else i'm emptying the input value.In my case i had to restrict other characters apart from numbers, you can change the regex based on your requirement
$(".numbersOnly").bind('paste', function(e) {
var self = this;
setTimeout(function(e) {
var val = $(self).val();
if (val != '0') {
var regx = new RegExp(/^[0-9]+$/);
if (!regx.test(val)) {
$(".numbersOnly").val("");
}
$(this).val(val);
}
}, 0);
});