How would you modify this regex to only allow letters and numbers?
I thought by putting that it must have at least 2 uppercase letters, lowercase letters and digits, that it would limit the expression to just those types of characters. But it allows unwanted characters like tildes and such.
/^[\s]*((?=([^\s]*\d){2,})(?=([^\s]*[a-z]){2,})(?=([^\s]*[A-Z]){2,})[^\s]{8,16})[\s]*$/
Here’s a way to do it using a few needles. fiddle
If you want to limit the size to being between X and Y replace
/^[A-Za-z0-9]+$/with/^[A-Za-z0-9]{X,Y}$/. Pretty simple, eh?