-4
我需要一個正則表達式來驗證電話號碼(含國家代碼),它應當遵循以下條件正則表達式,以便與國家代碼******中國
1 - There should be at max 4 digits in between + and - .
2 - Phone number shall be a combination of +,- and digits
3 - 0 shall not be allowed after -
4 - After - only 10 digits are allowed
如
1 - +91234-1234567 - Fail (1st Condition fails)
2 - +9123-1234567 - Pass
3 - + - Fail (2nd condition fails)
4 - - - Fail (2nd condition fails)
5 - 91234545555 - Fail (2nd condition fails)
6 - +91-- Fail (3rd Condition fails)
7 - +91-12345678910 - Fail (4th condition fails)
請幫我在這。提前致謝。
沒有產生超越知識正則表達式和學習,我知道的一個工具。對於大多數正則表達式,我通常會找到一個衆所周知的,經過良好測試的正則表達式來匹配已知格式。 – jdphenix
使用超前而不是'\ + \ d {1,4} - [1-9] \ d {,9} \ b'有沒有好處? –
@vivek試試看,不明白爲什麼不。 – jdphenix