Skip to content

Instantly share code, notes, and snippets.

@larodiel
Last active November 11, 2021 20:37
Show Gist options
  • Save larodiel/dc495aeeb837b69e11ffbea5edca85f8 to your computer and use it in GitHub Desktop.
Save larodiel/dc495aeeb837b69e11ffbea5edca85f8 to your computer and use it in GitHub Desktop.
Useful regEx
USER_NAME = "^[A-Za-z0-9_-]{min number of character,max number of character}$";
TELEPHONE = "(^\\+)?[0-9()-]*";
TELEPHONE_OPTIONAL = "^($|(^\\+)?[0-9()-]*)$"
EMAIL = "^([a-zA-Z0-9\.\_\+\-]+)@([a-zA-Z0-9\-]+)(\.[a-zA-Z]+)+$";
EMAIL_OPTIONAL = "^($|[a-zA-Z0-9_\\.\\+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-\\.]+)$";
WEB_URL = "^($|(http:\/\/|https:\/\/|\/\/)?(www.)?([a-zA-Z0-9]+).[a-zA-Z0-9]*.[a-z]{3}.?([a-z]+)?)$";
WEB_URL_YOUTUBE_BE = "https?\\:\\/\\/(www\\.)?youtu(\\.)?be(\\.com)?\\/.*(\\?v=|\\/v\\/)?[a-zA-Z0-9_\\-]+";
POSTAL_ADDRESS = "[a-zA-Z\\d\\s\\-\\,\\#\\.\\+]+";
FIELD_NOT_EMPTY = "[^\\s]*";
PINCODE = "^([0-9]{6})?$";
IFSC_CODE = "^[^\\s]{4}\\d{7}$";
SWIFT_CODE = "^([0-9]{10})?$";
PINCODE = "^([0-9]{6})?$";
---- PASSWORD PATTERNS ----
Minimum eight characters, at least one letter and one number:
^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{8,}$
--------
Minimum eight characters, at least one letter, one number and one special character:
^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*#?&])[A-Za-z\d@$!%*#?&]{8,}$
--------
Minimum eight characters, at least one uppercase letter, one lowercase letter and one number:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$
--------
Minimum eight characters, at least one uppercase letter, one lowercase letter, one number and one special character:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
--------
Minimum eight and maximum 10 characters, at least one uppercase letter, one lowercase letter, one number and one special character:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment