gpt4 book ai didi

regex - AngularJS - 使用正则表达式从输入框中删除前导和尾随空格

转载 作者:太空狗 更新时间:2023-10-29 15:28:09 24 4
gpt4 key购买 nike

我正在编写一个正则表达式 (regex),用于在具有以下条件的输入框中添加多个电子邮件 ID:

  1. 多个电子邮件 ID 必须用逗号分隔 ,
  2. 需要至少有一个电子邮件 ID
  3. 输入字段中不应有任何空格。

所以我创建了这个正则表达式:

^(([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+([,.](([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5}){1,25})+)*$

我在 regex101.com 上对其进行了测试,它的工作非常顺利 https://regex101.com/r/bU7rU8/1

但是当我将它与代码集成时,它可以工作,但在前导和尾随空格上失败

这是演示链接:http://jsfiddle.net/2G8gA/330/

最佳答案

AngularJS 默认修剪输入,因此您需要使用 ng-trim="false" 将前导和尾随空格传递给您的 pattern 正则表达式。

参见 documentation :

ngTrim (optional)

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)

关于regex - AngularJS - 使用正则表达式从输入框中删除前导和尾随空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32135035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com