去掉文本框前后的空格(JS+JQuery)
2024-08-31 05:31:44
表单验证时,需要去除文本框前后的空格才可以正确通过验证。以前看到过一句话:任何设计和代码都要对用户足够宽容。 <input type="text" class="phone">
<input type="button" id="btn" value="过滤"> 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,'');
最新文章
- 二叉树的创建和遍历(C版和java版)
- Android popupwindow使用心得(一)
- activiti工作流的web流程设计器整合视频教程 SSM 和 独立部署
- Angular Mobile UI API文档
- Ngui中Sprite,SlicedSprite,Tiled Sprite,FilledSprite的区别
- 跟着百度学PHP[4]OOP面对对象编程-10-静态关键字static
- 水流雨渍shader
- Java对象初始化详解
- 纯原生js移动端城市选择插件
- Xcode8.3 添加iOS10.3以下旧版本模拟器
- mysql启动时报错:Starting MySQL... ERROR! The server quit without updating PID file (/opt/mysql/data/mysql.pid) 的解决方法
- canvas图形编辑器
- [逆向工程] 二进制拆弹Binary Bombs 快乐拆弹 详解
- asp+SqlServer2008开发【第四集:windows server 2008 r2的操作记录】
- android抽屉效果
- [LeetCode] Shortest Word Distance I &; II &; III
- 伸展树(Splay Tree)进阶 - 从原理到实现
- air for android 使用ANE来获取安卓手机IMEI号
- C++编写DLL动态链接库的步骤与实现方法
- Scrum 项目2.0 3.0