help with lastname regex in c# code

  • Thread starter Thread starter dje
  • Start date Start date
D

dje

Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.
 
thx Igor and Robby!

Igor said:
Regex regex = new Regex("[a-zA-Z '-]+");


dje said:
Regex regex = new Regex("/[a-zA-Z '-]/");
Match match;
match = regex.Match(this.LastName.Text);
if(!match.Success)
{
sb.Append("Last name invalid. ");
returnValue=false;
}
with the input "jones", match.Success always fails. Is there something
wrong with my regular expression or am I not using Regex correctly?
Thanks.
 
Back
Top