I am trying to retrieve all the phone numbers from a text file using regular expression.
I have written below code for same.
import re
num=input('Enter valid number')
match=re.fullmatch('[6-9+9191]\d{10,13}',num)
if match!=None:
print('Mobile number is valid')
else:
print('Invalid Mobile number')
I have created pattern to search for numbers starting with 6-9 or +91 or 91 and having length between 9-13. By evaluating above code and if I enter '+919492556' or '987564321' or '919765893146' I'm getting output as valid mobile number,which is not desirable one. I want it to consider different conditions for different mobile number formats in order to correctly validate phone number entered in any format mentioned above. Thanks in advance. My output should be like +91875643 - Invalid mobile number +917465234567 - valid mobile number 917895436271 - Valid mobile number 91945637238 - Invalid mobile number 8765439254719 - Invalid mobile number 8796453271 - Valid mobile number