user2854563
user2854563

Reputation: 268

+ Sign With Number Regex

I want to check if the string has + sign in the beginning and the string is numeric with not more then 15 integers. Also the string shouldn't have any special characters or - in between the integers.

I'm using this regex: /\+?(?:(?:63)|0)*[.-]?9[0-9]{2}[.]?[0-9]{3}[.]?[0-9]{3,4}/Ui

But it shows error if the string doesn't have 9 after + sign. e.g. if I use +891234567 then it shows error.

Please help

Upvotes: 0

Views: 49

Answers (2)

gpmurthy
gpmurthy

Reputation: 2427

If I understand what you are looking for the following regex should help...

^\+\d{1,15}

Good Luck!

Upvotes: 0

Floris
Floris

Reputation: 46365

A "start with + followed by 1 to 15 digits" expression would be

^\+[[:digit:]]{1,15}

This is obviously not what you want but it's not clear from the question what you are hoping to do besides the above. Please use this to explain better what you actually want.

Upvotes: 1

Related Questions