How can I validate a string using Regular Expressions to only allow alphanumeric characters in it?
(I don\'t want to allow for any spaces either).
^\w+$ will allow a-zA-Z0-9_
^\w+$
a-zA-Z0-9_
Use ^[a-zA-Z0-9]+$ to disallow underscore.
^[a-zA-Z0-9]+$
Note that both of these require the string not to be empty. Using * instead of + allows empty strings.
*
+