Q:

Regular expression for comma seperated name search with wild card

Right now I am using multiple if conditions to valid the input for search by name with wildcard(*). Since I have multiple 'if' with inner 'if' statements I am trying to use regular expression to validate my input. I want to use this expression in both front end and back end.
Appreciate if anyone can help.
Validating rules are follow

Input is last name, first name i.e. separated by comma.
Must have at least two characters while using wild card search.
Valid wildcard character is '*' only.
At most two wildcard characters can be used.
No consecutive wild cards.
If no wild card used no constraint on length of characters in both last and first name.

Some of the valid inputs are:
 - hopkins, johns
 - h, j
 - ho*, jp*
 - *ins, johns
 - *op*, john*

Some of the invalid inputs are:
 - hopkins johns
 - h*, johns
 - hop**, joh*
 - h*pk*n*

If regular expression not going to be complex we can consider this as valid otherwise it OK to consider this as invalid
 - ho*in*, jo*

In short general name format is
 [*]XX[*], [*]XX[*]
 where [] ==> Optional
       X  ==> A-Z, a-z
       XX ==> length 2 or more if wild card used

A:

With the help of @Amit_Joki answer I wrote the following code and its working fine.
var nameArray = [...];
var re = /\*?[a-zA-Z]{2,}\*?, \*?[a-zA-Z]{2,}\*?/;
for (var i = 0; i < nameArray.length; i++) {
  if(nameArray[i].indexOf(',') < 0  || 
    (nameArray[i].indexOf('*') >= 0 && !re.test(nameArray[i]))) {
    console.log(nameArray[i] + ": Invalid");
  } else {
    console.log(nameArray[i] + ": Valid");
  }       
}

