Skip to content

Instantly share code, notes, and snippets.

@gatero
Created September 20, 2015 14:19
Show Gist options
  • Select an option

  • Save gatero/27546ec6e79a89a8f466 to your computer and use it in GitHub Desktop.

Select an option

Save gatero/27546ec6e79a89a8f466 to your computer and use it in GitHub Desktop.
window.RegularExpression =
number : /^[0-9]+$/
letters : /^[a-zA-Z_áéíóúñ\s]*$/
alphanumeric : /^[a-zA-Z0-9]+$/
latin_letters : /^[a-zA-ZáéíóúàèìòùÀÈÌÒÙÁÉÍÓÚñÑüÜ_\s]+$/
email : /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,4}$/
password : /^([a-z]+[0-9]+)|([0-9]+[a-z]+)/i
url : /^(ht|f)tps?:\/\/\w+([\.\-\w]+)?\.([a-z]{2,6})?([\.\-\w\/_]+)$/i
localhost : /^http:\/\/(localhost|127\.0\.0\.1)/
zip_code : /^([1-9]{2}|[0-9][1-9]|[1-9][0-9])[0-9]{3}$/
NIF : /^\d{8}[a-zA-Z]{1}$/
CIF : /^[a-zA-Z]{1}\d{7}[a-zA-Z0-9]{1}$/
NIE : /^[XxTtYyZz]{1}[0-9]{7}[a-zA-Z]{1}$/
VISA : /^4[0-9]{3}-?[0-9]{4}-?[0-9]{4}-?[0-9]{4}$/
MASTERCARD : /^5[1-5][0-9]{2}-?[0-9]{4}-?[0-9]{4}-?[0-9]{4}$/
date : /^([0-9]{2}\/[0-9]{2}\/[0-9]{4})$/
floatRegex : /[-+]?([0-9]*\.[0-9]+|[0-9]+)/
number1to50Regex : /(^[1-9]{1}$|^[1-4]{1}[0-9]{1}$|^50$)/gm
creditCardRegex : /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/
usernameRegex : /^[a-z0-9_-]{3,16}$/
passwordRegex : /^[a-z0-9_-]{6,18}$/
phoneNumber : /^[0-9-()+]{3,20}/
dateRegex : /(\d{1,2}\/\d{1,2}\/\d{4})/gm
dateMMDDYYYRegex : /^(0[1-9]|1[012])[- \/.](0[1-9]|[12][0-9]|3[01])[- \/.](19|20)\d\d$/
dateDDMMYYYRegex : /^(0[1-9]|[12][0-9]|3[01])[- \/.](0[1-9]|1[012])[- \/.](19|20)\d\d$/
urlRegex : /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
domainRegex : /(.*?)[^w{3}\.]([a-zA-Z0-9]([a-zA-Z0-9\-]{0,65}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/igm
domainRegex : /[^w{3}\.]([a-zA-Z0-9]([a-zA-Z0-9\-]{0,65}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}/igm
domainRegex : /(.*?)\.(com|net|org|info|coop|int|com\.au|co\.uk|org\.uk|ac\.uk|)/igm
subDomainRegex : /(http:\/\/|https:\/\/)?(www\.|dev\.)?(int\.|stage\.)?(travel\.)?(.*)+?/igm
imageRegex : /([^\s]+(?=\.(jpg|gif|png))\.\2)/gm
imgTagsRegex : /<img.+?src=\"(.*?)\".+?>/ig
imgPNG : /<img.+?src=\"(.*?.png)\".+?>/ig
rgbRegex : /^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/
hexRegex : /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
htmlTagRegex : /^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
jsTagsRegex : /<script.+?src=\"(.+?\.js(?:\?v=\d)*).+?script>/ig
cssTagsRegex : /<link.+?href=\"(.+?\.css(?:\?v=\d)*).+?>/ig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment