I am struggling to combine multiple separate regex validations into one for my mobile number validation requirements. The criteria include validating mobile numbers with a country code or starting with 00, as well as checking if they contain an extension number (2-5 digits) separated by a #.
Here is an example of a valid number:
+919986040933
00919986040933
+919986040933#12
+919986040933#123
+919986040933#1234
+919986040933#12345
The current regex patterns I have for validation are:
var phoneRegexWithPlus = "^((\\+)|(00))[0-9]{10,14}$";
var phoneRegexWithZero = "^((\\+)|(00))[0-9]{9,12}$";
var phoneRegexExtension = "^[0-9]{2,5}$";
Currently, I am checking whether the number contains a # symbol, and if so, splitting it to match the number and extension parts separately where the extension comes after the hash.
My challenge now is to create a single regex that combines all three validations above. Can anyone help me with this as I am not proficient in regex? Thank you in advance.