Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有这个只接受数字的 mobileNumber 正则表达式"[1-9][0-9]*"。 但我需要在开始时有一个可选的 + 。但用户不能在开头输入 +。 例如。+9089098909 例如。9089098909 例如 +919089098909 我最多可以接受 13 个字符。 我正在做这件事。谁能告诉如何解决这个问题?
"[1-9][0-9]*"
放在\+?正则表达式的开头。
\+?
您在^\+?\d{,13}$. 这可确保您的号码不超过 13 位,并且前面有一个可选的 +。
^\+?\d{,13}$