I realized it was tricky, I guess you might have to set several rules for this and change the formula according to the input in the field.
I was capturing first name and last name into same field and then if it was not in the format I wanted, I wanted to convert it into that format.