What is the regex to match alphanumeric 6 character words, separated by space or comma

I am newbie in RegEx and trying to design a RegEx which could match the String like below:

pattern 1 separated by comma and a space: KEPM39, JEMGH5, HEPM21 … (repeat)

pattern 2 separated only by a space: KEPM39 JEMGH5 HEPM21 … (repeat)

pattern 3 separated only by a comma: KEPM39,JEMGH5,HEPM21 … (repeat)

this is my concept: "^[a-zA-Z0-9]{6,}[,\s]+$" but it seems wrong.

#I want to validate the whole string, and I use javascript & html to validate user input. (textarea)

#duplicate change to repeat to be more suitable.

function validate(){
    var term = "JEPM34, KEPM11 ";
    var re = new RegExp("^[a-zA-Z0-9]{6,}[,\s]+$");
    if (re.test(term)) {
        return true
    } else {
        return false
    }
}

thanks you in advance!

17 thoughts on “What is the regex to match alphanumeric 6 character words, separated by space or comma”

  1. Everything is very open with a very clear clarification of the issues.
    It was really informative. Your website is very useful. Thank you
    for sharing!

    Reply

Leave a Comment