ArunK
ArunK

Reputation: 67

Javascript - Regex for comma-separated alphanumeric

I need regex for

validating comma separated alphanumeric String with length of 3-5 chars.

string may or may not contain commas.

each string will MUST have 3 to 6 numbers and One M in the end.

example-

12345M
1234M,12345M,11111M

Upvotes: 0

Views: 1308

Answers (1)

Fabrizio Calderan
Fabrizio Calderan

Reputation: 123397

Try this

var re = /^(\d{3,6}M\,)*\d{3,6}M$/

Example code

console.log(re.test("1234M,12345M,11111M"));  // true
console.log(re.test("12345M"));               // true
console.log(re.test("12345M,"));              // false

Upvotes: 3

Related Questions