3 回答

TA貢獻(xiàn)1845條經(jīng)驗(yàn) 獲得超8個贊
您可以使用this正則表達(dá)式
^(?!^[.])(?!.*[.]$)(?!.*[.]{2})[\w.'-]{1,64}$
正則表達(dá)式分解
^ #Start of string
(?!^[.]) #Dot should not be in start
(?!.*[.]$) #Dot should not be in start
(?!.*[.]{2}) #No consecutive two dots
[\w.'-]{1,64} #Match with the character set at least one times and at most 64 times.
$ #End of string
更正您的正則表達(dá)式
-
不應(yīng)介于字符類之間。它表示范圍。避免在兩者之間使用它[a-zA-Z0-9_]
相當(dāng)于\w

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個贊
這是一個似乎有效的模式:
^(?!.*\.\.)[a-zA-Z0-9_'-](?:[a-zA-Z0-9_'.-]{0,62}[a-zA-Z0-9_'-])?$
以下是正則表達(dá)式模式的解釋:
^ from the start of the string
(?!.*\.\.) assert that two consecutive dots do not appear anywhere
[a-zA-Z0-9_'-] match an initial character (not dot)
(?: do not capture
[a-zA-Z0-9_'.-]{0,62} match to 62 characters, including dot
[a-zA-Z0-9_'-] ending with a character, excluding dot
)? zero or one time
$ end of the string
添加回答
舉報(bào)