The rules for this test are:
- Must contain letters and numbers
- May contain these special characters anywhere within the string:
Number sign (#)
Minus (-)
Full stop (.)
Slash (/)
Space ( )
- May not contain any other special characters
- May not consist of only letters
- May not consist of only letters and/or the special characters
- May not consist of only numbers
- May not consist of only numbers and/or the special characters
- The numbers, letters and special characters may be in any order
Examples of desired matches:
445b
apt 445a
Apt. #445
Apt 445
Apt-445
Apt - 445
apt445
apt#445
apt/445
APT-445a
APT - 445c
Apt# 445b
Apt. #445-c
22 Elm St.
Examples of non-matches:
apt four forty five
Elm St.
Elm St
Elm Street
445
445 445
445-445
#445
(any or all of the special characters by themselves)
41686d6564's answer below is extremely close but in my original question I failed to specify that spaces are part of the special characters:
/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z0-9\-#\.\/]+$/
I've tried on my own to get the space special character incorporated but I don't get the desired outcome.
See the live example. Live Example