ng-pattern 不能含有空格及特殊字符 应该怎么写呢?
/^[\u4e00-\u9fa5\w]+$/
无法屏蔽首尾空格
这个不是ng-pattern或者你的正则写错了原因,而是因为angular的input的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" />
应该就好了,还有问题可以留言