How can I strip all non digits in a string except the first character?

后端 未结 5 1874
我在风中等你
我在风中等你 2021-01-19 14:34

I have a string that I want to make sure that the format is always a + followed by digits.
The following would work:

String parsed = input         


        
5条回答
  •  日久生厌
    2021-01-19 15:14

    try this

    1- This will allow negative and positive number and will match app special char except - and + at first position.

    (?!^[-+])[^0-9.]
    

    2- If you only want to allow + at first position

    (?!^[+])[^0-9.]
    

提交回复
热议问题