[英]Regular expression to allow alphabets and onle one occurrence of select special characters
[英]I am looking to write a regular expression to allow 6 characters and within the 6 characters, It should only allow 3 alphabets and 3 numbers
我希望編寫一個正則表達式以允許 6 個字符,並且在 6 個字符內,它應該只允許 3 個字母和 3 個數字。
它就像密碼驗證:
^(?=(?:.*[a-zA-Z]){3})(?=(?:.*[0-9]){3})[a-zA-Z0-9]{6}$
錨定字符串的開頭和結尾僅強制 6 個字符。
^
# Must have 3 letters
(?=
(?: .* [a-zA-Z] ){3}
)
# Must have 3 numbers
(?=
(?: .* [0-9] ){3}
)
# Must have 6 characters
[a-zA-Z0-9]{6}
$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.