javascript - Backspace is not working in Textarea of My Form on Mozila browser -


function onlyalphabets(e, t) {    try {      if (window.event)  {        var charcode = window.event.keycode;      }      else if (e) {        var charcode = e.which;      }      else { return true; }      if ((charcode > 64 && charcode < 91) || (charcode > 96 && charcode < 123))        return true;      else        return false;    }    catch (err) {      alert(err.description);    }  }    function isnumber(evt) {    evt = (evt) ? evt : window.event;    var charcode = (evt.which) ? evt.which : evt.keycode;    if (charcode > 31 && (charcode < 48 || charcode > 57)) {      return false;    }    return true;  }              $('input.facebookurl').keyup(function(){    if (      ($(this).val().length > 0) && ($(this).val().substr(0,24) != 'http://www.facebook.com/')      || ($(this).val() == '')    ){      $(this).val('http://www.facebook.com/');        }  });
<table align="center">    <tr>      <td>        <input name="firstname"  class="text_area"  maxlength=20 placeholder="name" type="text" onkeypress="return onlyalphabets(event,this)" required  id="validname" value="" />      </td>    <tr>      <td>        <input type="text" onkeypress="return isnumber(event)" id="volpincode" maxlength=7 name="pincode"  value="" required  placeholder="pincode" class="text_area">      </td>      <td><input style="width:300px" type="text" onkeypress="return keyup(event)" class="facebookurl" name="facebook" value="http://www.facebook.com/$facebook"></td>      <td>        <input style="width:30px" disabled="disabled" type="text" name="facebook" value="+91" />      </td>    </tr>    </tr>  </table>

i trying validate name , pin code, such in name field alphabets have enter not other characters , in pincode numbers should enter. form working in google chrome fine, firefox when enter , try delete text in text field, characters not getting deleted.

to validate alphabets name use below code:

$(document).on("keydown", "#nametextboxid", function (e) {                 if (e.ctrlkey || e.altkey) {                     e.preventdefault();                  } else {                      var key = e.keycode;                     if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key == 9))) {                         e.preventdefault();                     }                 }             }); 

to validate numbers pin use below code:

 $(document).on("keydown", "#pinid", function (e) {                 if (e.shiftkey || e.ctrlkey || e.altkey) { // if shift, ctrl or alt keys held down                     e.preventdefault();         // prevent character input                 } else {                     var n = e.keycode;                     if (!((n == 8)              // backspace                             || (n == 46)                // delete                             || (n >= 35 && n <= 40)     // arrow keys/home/end                             || (n >= 48 && n <= 57)     // numbers on keyboard                             || (n >= 96 && n <= 105)                             || (n == 9))   // number on keypad                     ) {                         e.preventdefault();                         // alert("in if");                         // prevent character input                     }                 }             }); 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -