簡體   English   中英

不接受的正則表達式。 在 React 中 email 地址的末尾

[英]Regular expression to not accept . at the end of the email address in React

我想構造一個正則表達式 where . 不允許作為 email 地址的最后一個和第一個字符(例如: .abc.@gmail.com不應被接受)。 此外,我還有另一個要求,即..地址中的任何地方都不允許有 2 個連續的周期(例如: abc...def@gmail.com )。

我目前使用的正則表達式是: let regEx = new RegExp(/^[a-zA-Z0-9+_.-]+@(\[(\d{1,3}\.)(([a-zA-Z\d-]+\.)+))([a-zA-Z]{2,15}|\d{1,3})(\]?)/); .

我可以在修改上述正則表達式以滿足我的要求方面獲得一些幫助嗎?

PS:我對正則表達式知之甚少。

添加您的 2 個新要求,我們可以嘗試:

^(?!.*\.\.)[\p{L}\p{N}\s,_-][\p{L}\p{N}\s,._-]*[\p{L}\p{N}\s,_-]$

解釋:

^                        from the start of the email
    (?!.*\.\.)           no two or more consecutive dots
    [\p{L}\p{N}\s,_-]    first character is not dot
    [\p{L}\p{N}\s,._-]*  zero or more allowed characters, including dot
    [\p{L}\p{N}\s,_-]    last character is not dot
$                        end of the email

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM