views:

201

answers:

2

I have the following regex expression on a dev machine that is running .NET 3.5 and it works as designed. However when it is deployed to our test environment (which is running .NET 2.0) it doesn't work right and always seems to return false. Does anyone know what the culprit may be? Thanks

using System.Text.RegularExpressions;

protected void emailContactCheck(object source, ServerValidateEventArgs args)
{
  string[] allContacts = this.Contacts.InnerText.ToString().Split(";,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  Regex rx = new Regex(@"^(([^<>()[\]\\.,;:\s@\""]+"
                    + @"(\.[^<>()[\]\\.,;:\s@\""]+)*)|(\"".+\""))@"
                    + @"((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}"
                    + @"\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+"
                    + @"[a-zA-Z]{2,}))$", RegexOptions.IgnoreCase);
  foreach (String contact in allContacts)
  {
    if (!rx.IsMatch(contact.Trim()))
    {
      args.IsValid = false;
      return;
    }
  }
  args.IsValid = true;
}
A: 

I would try to set the .Net version of your dev machine to .Net 2.0 too. Can be done on the project build properties. You should always use the same version as on your test/production system.

Then you can try to check whether you can reproduce the problem also on your dev machine running .Net 2.0.

Juri
A: 

According to regular-expressions.info, there are no differences in regex support between .NET 2.0 and 3.x, so the problem is probably not with the regex engine.

Tim Pietzcker