Last active
December 19, 2018 14:02
-
-
Save sakhayadeep/986065aa5a167a3100f842d236efd0a9 to your computer and use it in GitHub Desktop.
Python code for Indian Mobile Number validation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Indian Mobile Number validation criteria: | |
The Country calling code for india is +91 | |
valid pre-fixes are 0,91,+91 . | |
All mobile phone numbers are 10 digits long (not including a pre-fix). | |
The first digit should contain number between 9,8,7 or 6. | |
Rest of the nine digits can be any number between 0 to 9. | |
''' | |
#function for validating | |
def ph_validate(num): | |
country_code = '0' | |
if(len(num)>10): | |
country_code=num[:len(num)%10] | |
num=num[len(num)%10:] | |
first_digit=['6','7','8','9'] | |
valid_pre_fix=['0','91','+91'] | |
if(len(num)==10 and num.isdigit()): | |
if(country_code in valid_pre_fix and num[0] in first_digit): | |
return("Valid") | |
else: | |
return("Invalid") | |
else: | |
return("Invalid") | |
#driver code | |
num=input("Enter the number : ") | |
result=ph_validate(num) | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment