Skip to content

Instantly share code, notes, and snippets.

@bkanhu
Last active February 20, 2023 18:51
Show Gist options
  • Save bkanhu/bf07ba56db19669a353a1bd94080dc15 to your computer and use it in GitHub Desktop.
Save bkanhu/bf07ba56db19669a353a1bd94080dc15 to your computer and use it in GitHub Desktop.
REGEX

INDIAN PIN CODE:

/^[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.

Indian phone numbers

/^[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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment