nihulus
nihulus

Reputation: 1495

regular expression for is empty space

I'm suresomeone of you know how to do this easily, I am trying to validate my inputs that only allows numbers, characters and/or an empty space which mean nothing in a string "", so I have /^[0-9a-zA-Z]+$/ only missing that empty space in there. Seems I can't find the express for it, so I tried to create a variabel var emptyStr = "" and put it in there but don't really know how to write the correct syntax.

Upvotes: 0

Views: 177

Answers (2)

mcbex
mcbex

Reputation: 444

/^[A-z0-9\s]*$/

The \s will also capture spaces

Upvotes: 0

basher
basher

Reputation: 2401

Use * rather than +. * is 0 or more times. + is 1 or more times.

/^[0-9a-zA-Z]*$/

Upvotes: 2

Related Questions