-3

I am searching for a regular expression for allowing alphanumeric and spaces in JavaScript. I tried Googling but wasn't able to find that. For alphanumeric i am using '^[a-zA-Z0-9]+$'

Can anyone help me out with this?

Thanks in advance.

cloned
  • 6,346
  • 4
  • 26
  • 38
Anand R
  • 51
  • 1
  • 7

2 Answers2

1

Just add a space; ^[a-zA-Z0-9 ]*$

Increase your google-fu: https://www.google.com/search?q=regex+allow+spaces

I'm not sure how or what you tried googling but there's heaps of results to your question... Including this StackOverflow Post where your question has been answered in great detail.

Dexterians
  • 1,011
  • 1
  • 5
  • 12
1

You might be surprised but you literally only had to add a space in between the square brackets like so:

'^[a-zA-Z0-9 ]*$'

RegExp is challenging but I have found a resource by google that can be quite helpful here.

CRUD DS
  • 456
  • 2
  • 5