Validate html text input as it's typed

前端 未结 9 686
再見小時候
再見小時候 2020-11-27 16:36

What\'s the best way of validating an HTML text input as it\'s typed? All ways I know of doing it has some drawbacks:

  1. Using $.keypress you only

9条回答
  •  孤独总比滥情好
    2020-11-27 16:59

    Here is the code

    function validatephone(xxxxx) 
    {
      var maintainplus = '';
      var numval = xxxxx.value
      if ( numval.charAt(0)=='+' )
      {
        var maintainplus = '';
      }
      curphonevar = numval.replace(/[\\A-Za-z!"£$%^&\-\)\(*+_={};:'@#~,.Š\/<>\" "\?|`¬\]\[]/g,'');
      xxxxx.value = maintainplus + curphonevar;
      var maintainplus = '';
      xxxxx.focus;
    }

提交回复
热议问题