DEV Community

Cover image for Pincode,Gmail and Mobile Number Validation in Python
Harini
Harini

Posted on • Edited on

Pincode,Gmail and Mobile Number Validation in Python

1. Check whether a given number is a valid 6-digit pincode or not.

def pincode(pc):
    if pc//100000!=0 and pc//100000<=9:
        print("Yes")
    else:
        print("No")
pincode(int(input("Enter a pincode :")))
Enter fullscreen mode Exit fullscreen mode

Output

2. Check whether a given email ID is a valid Gmail address or not.

def verify_Gmail(Gmail):
    if Gmail[-10:]=="@gmail.com":
        i=0
        gmailcopy=Gmail[0:len(Gmail)-10]
        while i<len(gmailcopy):
            current=gmailcopy[i]
            i+=1
            if current>="a" and current<="z":
                continue;
            elif current>="A" and current<="Z":
                continue;
            elif current>="0" and current<="9":
                continue;
            elif current=="." or current=="_":
                continue;
            else:
                return False
        return True
    else:
        return False

if verify_Gmail(input("Enter Your Gmail :")):
    print("valid")
else:
    print("invalid")

Enter fullscreen mode Exit fullscreen mode

Output

3. Check whether a given input is a valid Indian mobile number or not.

def verify(mobnum):
    index=0
    while index<len(mobnum):
        if mobnum[index]>="0" and mobnum[index]<="9":
            index+=1
            continue;
        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 : ")));
Enter fullscreen mode Exit fullscreen mode

Output

Top comments (0)