sitanshu
sitanshu

Reputation: 65

Javascript regular expression to not allow space in a textfield

I have a text field which takes emails, more than one email is separated by comma, so I want a regular expression which will not allow space in that text field i.e the space bar will not work. pls help.. Thanks.

Upvotes: 2

Views: 5260

Answers (2)

Brian Moeskau
Brian Moeskau

Reputation: 20419

Don't break the expected user input model. Clean up the input after submission (split on comma then trim each part). Breaking the spacebar will just annoy people.

Upvotes: 1

jonvuri
jonvuri

Reputation: 5920

maskRe: /[^ ]/

[^ ] means anything except the space character. If you wanted to match all whitespace and not just the space character, use /\S/

Upvotes: 1

Related Questions