/^[1-9][0-9]{5}$/
Here's what this regex means:
^
: This anchor matches the start of the string.[1-9]
: This character set matches any digit from 1 to 9 (the first digit of the PIN code cannot be 0).[0-9]{5}
: This character set matches any five digits from 0 to 9 (the remaining digits of the PIN code).$
: This anchor matches the end of the string. Put together, this regular expression matches any six-digit string that starts with a digit from 1 to 9 and ends with five digits from 0 to 9, which is the format of a valid Indian PIN code.
/^[6-9]\d{9}$/
Here's what this regex means:
^
: This anchor matches the start of the string.[6-9]
: This character set matches any digit from 6 to 9 (the first digit of the Indian phone number must be between 6 and 9).\d{9}
: This matches any digit exactly nine times (the remaining nine digits of the Indian phone number).$
: This anchor matches the end of the string.
/^(?:\+91|0)?[6-9]\d{9}$/
- This modified regular expression matches a string that starts with either "+91" or "0" (both optional), followed by a digit between 6 and 9, and then nine digits.
Here are the results for the adjusted regex ^(?:\+91|0)?[6-9]\d{9}$:
6854445254: ✅ Match
06854445254: ✅ Match
916854445254: ❌ No match (as intended)
+916854445254: ✅ Match
+919168544452: ✅ Match
09168544452: ✅ Match