I'm trying to write a regex for country code, which should limit to four characters maximum, only symbol allowed is a + sign. When the + is used, the + has to be in the beginning, and it should have at least one number.
Valid cases
+1
1
+12
12
+123
1234
Invalid cases
+
+1234
12345
1+
12+
<empty>
etc.
The expression that I have right now.
/(+d{1,3})/
Can it be more elegant?
-Thank you in advance!!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…