angularjs的ng-messages 正则应该怎么写?

ng-pattern 不能含有空格及特殊字符 应该怎么写呢?

/^[\u4e00-\u9fa5\w]+$/

无法屏蔽首尾空格

阅读 3k
1 个回答

这个不是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" />

应该就好了,还有问题可以留言

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题