Validate PIN codes

EasyRegEx Programs · 3 of 20

Write a Python program to validate 6-digit Indian PIN codes (not starting with 0).

Advertisement
Output
411001 True
011001 False
41100 False
560034 True

Approach

  1. [1-9]\d{5}.

Solution

Python
import re for pin in ["411001", "011001", "41100", "560034"]:    print(pin, bool(re.fullmatch(r"[1-9]\d{5}", pin)))
Output
411001 True
011001 False
41100 False
560034 True

Learn the concept

New to this topic? Read the lesson, then come back.

More regex programs

← All 20 RegEx Programs

Leave a Comment