Now my code is 100% Right way to verify mobile number exactly.
I checked some condition to confirm given number is mobile number.
condition 1 :
given numbers must be only 0 to 9 or + or empty space .
- above the condition is true, then only checks the next conditions.
- otherwise return characters and characters spl are not allow.
i created one function the name of verify. that function checks given given argument is only have 0 To 9.
condition 2 :
my second condition is checks the length of the given numbers, the length should be 10, then only enter in condition 2. else goes the next condition3.
okay, let come's to the condition 2
condition 2 is checks, Given numbers in first number must be greater than or equal to 6 and less than or equal to 9 and calling the verify function and argument is given number.
- above the both condition is true, return "Valid Mobile Number"
- above the both condition is false, return "check the first digit and space and plush not allowed".
Condition 3 :
condition 3 also checks the length of the given numbers, the length is must be 13, then only enter in condition 3. else goes the next condition 4.
let come's to the condition 3
condition 3 is checks the given first three numbers is == "+91"
- Above the condition is False, return "First three number should like +91"
-
above the condition is true, checks the next condition, next condition is checks the fourth digit is must be greater than or equal to 6 and less than or equal to 9 and calling the verify function and argument is given number except first three index.
- the both condition is true, return "Valid Mobile Number"
- the condition is false, return "check the fourth digit and plus and space not allow between the number"
condition 4 :
condition 4 is similar to condition 3, extra checks space.
condition 4 checks the length of the given numbers, the length is must be 14, then only enter in condition 4. else goes next .
condition 4,
checks the given first four ind is == "+91 "
- Above the condition is False, return "First four number should like +91 "
-
above the condition is true, checks the next condition, next condition is checks the fifth number is must be greater than or equal to 6 and less than or equal to 9 and calling the verify function and argument is given number except first four index.
- the both condition is true, return "Valid Mobile Number"
- the condition is false, return "check the fifth digit and, plus and space not allowed
FINAL :
given number is can't enter in any condition 2,3,4.
return "given number is invalid"
the function is return a string, So function must be call in print.
**
**and this is my code :
def verify(mobnum):
index=0
while index<len(mobnum):
if mobnum[index]>="0" and mobnum[index]<="9":
index+=1
else:
return False
return True
def mobile(n):
i=0
while i<len(n):
if(n[i]>="0" and n[i]<="9") or (n[i]=="+") or (n[i]==" "):
i+=1
else:
return "characters and special charactors not allowed"
if len(n)==10:
if n[0]>="6" and n[0]<="9" and verify(n):
return "valid";
else:
return "incorrect"
if len(n)==13:
if n[0:3]=="+91":
if n[3]>="6" and n[3]<="9" and verify(n[3:]):
return "valid"
else:
return "incorrect"
return "First three number should like +91"
if len(n)==14:
if n[0:4]=="+91 ":
if n[4]>="6" and n[4]<="9" and verify(n[4:]):
return "valid"
else:
return "incorrect"
return "First four number should like +91 "
return "Please Enter Your valid Mobile Number"
print(mobile(input("Enter Your Mobile Number : ")));
drop your ideas in comments
Top comments (2)
I think 🤔, when I enter + and space between the mobile number , that program cannot verify exactly
i'm currently working for solve that problem...