I am searching for a regular expression for allowing alphanumeric characters, -, _ or spaces in JavaScript/jQuery. I tried Googling but wasn\'t able to find that.
Ca
For me I wanted a regex which supports a strings as preceding. Basically, the motive is to support some foreign countries postal format as it should be an alphanumeric with spaces allowed.
So I ended up by writing custom regex as below.
/^([a-z]+[\s]*[0-9]+[\s]*)+$/i
Here, I gave * in [\s]* as it is not mandatory to have a space. A postal code may or may not contains space in my case.