表单验证时,需要去除文本框前后的空格才可以正确通过验证。以前看到过一句话:任何设计和代码都要对用户足够宽容。

<input type="text" class="phone">
<input type="button" >

jQuery - $.trim()
var tel = $('.phone').val();
var result = $.trim(tel);

JS - replace&正则
var tel = document.querySelector('.phone').value;
var result = tel.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g,'');

  

相关文章:

  • 2021-12-20
  • 2022-12-23
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2021-08-06
  • 2021-10-04
  • 2022-12-23
相关资源
相似解决方案