1

i search for a regex in JavaScript for Alphanumeric characters and the asterisk sign (*).

All i found is this:

  var regexAlphaNumWithAsterisk = new RegExp(/^[0-9a-zA-Z\*{*}]+$/);

I want to test this groups : "12*****" or "123456" or "BCDEFG" or "12*ABC" When I change my regexp like

var regexAlphaNum = new RegExp(/^[0-9a-zA-Z]+$/);

my validation for "123456" or "BCDEFG" is fine.

Can everyone help me with this?

1 Answer 1

4

You can just use regex literal for this:

var regexAlphaNum = /^[0-9a-zA-Z*]+$/;

No need to use RegExp constructor for this and * doesn't need to be escaped inside character class i.e. [...]

Sign up to request clarification or add additional context in comments.

1 Comment

How about /^[0-9a-z*]+$/i

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.