Regular Expression
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
Matching a password
/^[a-z0-9_-]{6,18}$/
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 timesMatching a slug
/^[a-z0-9-]+$/
beginning with the string, followed by one or more letters,numbers,or hyphens
for example: my-title-hereMatching 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.
- Matching a url
/^(https?"\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?$/