扫码关注官方订阅号
ng-pattern 不能含有空格及特殊字符 应该怎么写呢?
/^[\u4e00-\u9fa5\w]+$/
无法屏蔽首尾空格
这个不是ng-pattern或者你的正则写错了原因,而是因为angular的input的ngTrim属性默认为true
ngTrim
true
ngTrim (optional) boolean If set to false Angular will not automatically trim the input. This parameter is ignored for input[type=password] controls, which will never trim the input. (default: true) 也就是默认会对input的value默认进行去首尾空格的处理,这里你只需要加入
<input ng-trim="false" />
应该就好了,还有问题可以留言
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
这个不是ng-pattern或者你的正则写错了原因,而是因为angular的input的
ngTrim
属性默认为true
应该就好了,还有问题可以留言