Validate Iranian Mobile Numbers with Regex in Python
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This Python code validates Iranian mobile phone numbers using regular expressions. The pattern ^09[0-9]{9}$ ensures the number starts with 09 and is exactly 11 digits long.
- The number must start with 09.
- After 09, there should be exactly 9 digits (0-9).
- Any extra or fewer characters will cause the number to be invalid.
To use it, replace the txt variable with the desired phone number and run the script. It will print whether the number is valid or not.