HiDayurie Dave
HiDayurie Dave

Reputation: 1807

jQuery regex alphanumerics prevent symbol and space

Simple question,
I have jquery function alphanumers

var alphanumers = /^[a-zA-Z0-9- ]*$/;

it will not allowed all symbols.

But now I want the space including to be not allowed.

Any idea?

Upvotes: 1

Views: 82

Answers (1)

user2493235
user2493235

Reputation:

To also disallow space, change it to:

var alphanumers = /^[a-zA-Z0-9-]*$/;

This will allow any character A to Z in either upper- or lower-case, numbers 0 to 9 and the dash character.

Upvotes: 1

Related Questions