How do I use a regular expression to get a boolean?

Basically I just want to insure a username contains only a-z, 0-9, and underscore’s.

I think this regex will work /^([a-zA-Z0-9_-]+)$/ but I’m not sure how I can make Javascript use that to tell me whether or not a string contains characters other than those?

Any tips?

I think you’re looking for test()

The syntax may be a bit different than you’re used to, but looking at the examples should help.

1 Like

Aye, that looks about right. Thank you.

That can be done with a much shorter expression

/^\w+$/

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.