RegExp

Regular Expression

  1. Matching a username

    /^[a-z0-9_-]{3,16}$/
    
    ^:the begining of the line
    
    |: delimiters
    
    lowercase letter(a-z)number(0-9),and underscore,or a hyphen
    next, {3,16} makes sure that are at least 3 of those characters, but no more than 16.
    $: end of this line
    
  2. Matching a password

    /^[a-z0-9_-]{6,18}$/
    
  3. Matching a hex value

    /^#?([a-f0-9]{6}|[a-f0-9]{3})$/
    

    The question mark tells the parser that the preceding character in this case a number sign- is option
    next, inside the first group,we can have tow different situations.The first one is any lowercase letter between a and f or number six tiems. the vertical bar tells us that we also can have three lowercase letters between a and f or numbeers instead for three times

  4. Matching a slug

    /^[a-z0-9-]+$/
    beginning with the string, followed by one or more letters,numbers,or hyphens
    for example: my-title-here

  5. Matching an email

    /^([a-z0-9-.-]+)@([a-z0-9_.-]+).([a-z.]{2,6})$/

inside the first group, we match one or more lowcase letters, numbers,underscope,dots or hyphens. I have escaped the dot because a non-escaped dot means any character. after than,there must be @. then next is the domain name which must be:one or more lowercase letters, numbers, underscores, dots,or hyphens. then another escaped dot, then with the extension being two to six letters or dots.

  1. Matching a url
    /^(https?"\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?$/