Python Practice › RegEx Programs › Program 3
Validate PIN codes
Write a Python program to validate 6-digit Indian PIN codes (not starting with 0).
Output
411001 True 011001 False 41100 False 560034 True
Approach
[1-9]\d{5}.
Solution
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.