When creating an account, is there a way to check if the user has a middle name to be used?

Here are exampls of what I need:

John James Doe has a middle name, use john.j.doe

John Doe doesn’t have a middle name, don’t use john…doe, use john.doe

Use a ternary expression in the login-name to check if the user has a middle name:

String.IsNullOrWhiteSpace(Person.MiddleName)? Person.PreferredName + '.' + Person.LastName: Person.PreferredName + '.' + Person.InitialMiddleName + '.' + Person.LastName

This checks if the user has a middle name, if they don’t use FirstName.LastName, if they do use FirstName.InitialMiddleName.LastName