Skip to content

Instantly share code, notes, and snippets.

@re2005
Last active February 6, 2024 10:45
Show Gist options
  • Save re2005/d53c56b97b1f6265106cb12e36198cd0 to your computer and use it in GitHub Desktop.
Save re2005/d53c56b97b1f6265106cb12e36198cd0 to your computer and use it in GitHub Desktop.
Regular expression for common validators | alpha, date, kvk number, iban, zicode (NL)
const regexps = {
alpha: '[a-zA-Z .-]+',
alphaNumeric: '[a-zA-Z0-9À-ü ,.\'-]+',
sameChars: /^(?!.*(.)\1\1+)/i,
date: /^(?:(?:(?:[0]?[1-9]|1[0-9]|2[0-8])-(?:(0)?[1-9]|1[0-2])|(?:29|30)-(?:(0)?[13-9]|1[0-2])|31-(?:(0)?[13578]|1[02]))-[1-9]\d{3}|29-(0)?2-(?:[1-9]\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00))$/,
kvkNumber: /^[0-9]{8}$/,
btwNumber: /^[A-Za-z]{2}[0-9]{9}[A-Za-z][0-9]{2}$/,
phoneMobile: /(^(\(?(0031|0|\+31)\)?){1})( ?-?(6){1}\)?)(( ?|-)?[1-9]( ?|-)?){1}(( ?|-)?[0-9]( ?|-)?){7}$/,
phoneFixedThreeDigits: /(^(\(?(0031|0|\+31)\)?){1})( ?-?([0-9]){3}\)?)(( ?|-)?[0-9]( ?|-)?){6}$/,
phoneFixedFourDigits: /(^(\(?(0031|0|\+31)\)?){1})( ?-?([0-9]){2}\)?)(( ?|-)?[0-9]( ?|-)?){7}$/,
phoneFixedExceptions: /^( ?\(?((0)|(\+31)|(0031))\)? ?){1}?(| |-| ?\([0-9]*?\) ?)(800|900|906|909){1}.*$/,
phoneFixedMobileException: /^( ?\(?((0)|(\+31)|(0031))\)? ?){1}?(| |-| ?\([0-9]*?\) ?)(800|900|906|909|6){1}.*$/,
zipCode: /^[1-9][0-9]{3}[ -\\.]?[A-Za-z]{2}$/,
houseNumber: /^[0-9]{0,5}$/,
houseNumberExtension: /^(?!\s|-)(((?!\s{2})[A-Za-z0-9\s-])*)$/,
iban: /^([A-Z]{2})(\d{2})([A-Z\d]+)$/,
driversLicense: /^(?!0{10})([0-9]{10})$/i,
identityCard: /^[a-zA-Z]{2}(?!0{7})([a-zA-Z0-9]{6}[0-9]{1})$/i,
passport: /^[a-np-z]{2}[a-np-z0-9]{6}[0-9]$/i,
email: /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
};
export default regexps;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment