65.9K
CodeProject is changing. Read more.
Home

Validating Gender Dynamically using REGEX

starIconstarIconstarIconstarIconstarIcon

5.00/5 (1 vote)

Apr 19, 2012

CPOL
viewsIcon

9492

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 ) ) ...