Validating Gender Dynamically using REGEX





5.00/5 (1 vote)
This is an alternative for "Validating gender dynamically using REGEX"
Introduction
Given that you will likely need to have the gender in an enumerated value anyway, I would simply use what's built into the .NET enum
class. Something as simple as the following may be all you need.
public enum Gender
{
Unknown = 0
,
Female = 1
,
F = Female
,
Male = 2
,
M = Male
}
Gender g ;
if ( System.Enum.TryParse ( s , true , out g ) ) ...