1

I have asp:textbox control which is allow only number but i am facing some issue on Firefox v 53.0.3 other browser e.g Chrome & i.e,which is working fine. when i copy numbers and paste into the input box which should check is that number or not, while paste it i set the debug point on IsNumber and i see the e.charCode is getting "v", not sure why.

<asp:TextBox runat="server" ID="txtZip" AutoComplete="off" type="number" MaxLength="5" 
             size="5" data-val-mandatory="true"
             data-val-conditioncontrol="ZIPCODE" data-val-errormsg="Provide a valid zip"
             TabIndex="1" onkeypress="return IsNumber(event);">
</asp:TextBox>

function IsNumber(e) {
var keynum = GetKey(e);
if ((keynum >= 48 && keynum <= 57) || keynum == 8 || keynum == 9 || keynum == 0 || keynum == undefined) {
    return true;
} else {
    if (e.preventDefault) {
        e.preventDefault();
    }
    else {
        e.returnValue = false;
    }
}

function GetKey(e) {
    var keynum;
    if (window.event) // IE
     {
       keynum = e.keyCode;
     }
    else if (e.which) // Netscape/Firefox/Opera
     {
       keynum = e.keycode;
     }
    return keynum;}

Note: In Firefox when i right click and paste the value it's working fine but when i copy and paste it using keyboard it is not working.

  • 1
    Possible duplicate of [JavaScript get clipboard data on paste event (Cross browser)](https://stackoverflow.com/questions/2176861/javascript-get-clipboard-data-on-paste-event-cross-browser) – Seano666 Jun 05 '17 at 17:15

0 Answers0