I receive the above error compiling this email validating class:
using
System;using
System.Collections.Generic;using
System.Text;using
System.Text.RegularExpressions;using
System.Net.Mail;namespace
WindowsApplication1{
class Check{
public static bool isEmail(string inputEmail){
inputEmail = NullToString(inputEmail);
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$"; Regex re = new Regex(strRegex); if (re.IsMatch(inputEmail)) return (true); else return (false);}
}
}

Which Namespace contains NullToString ?
PawelWasilewski
He's passing in a string which has not been declared anywhere. I assume that he's meant to pass in the string that was an input parameter.
PeacError
There is no such thing as nulltostring. Best guess, it looks something like this:
private string NullToString (string s)
{
return (s== null) "" : s;
}
jreyes97
Thank you very much for your answers. Trying the code from PJ I get this error now:
Error 1 The name 'strRegex' does not exist in the current context
TJSR
20thCenturyBoy
public static bool isEmail(string inputEmail)
{
if( inputEmail == null || inputEmail.Lengt == 0 )
{
throw new ArgumentNullException( "inputEmail" );
}
const string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$";
Regex regex = new Regex(strRegex);
return regex.IsMatch(inputEmail);
}
NickP001
My best guess is that you are attempting to use the new string.IsNullOrEmpty method for parameter checking in your case.
You would do something like
if (string.IsNullOrEmpty(inputEmail))
throw new ArgumentNullException("inputEmail"):
// process as normal...
Regards,
Dave
GKRAO
Dylan Smith
public static bool isEmail(string inputEmail)
{
if( inputEmail == null || inputEmail.Lengt == 0 )
{
throw new ArgumentNullException( "inputEmail" );
}
const string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$";
Regex regex = new Regex(expression);
return regex.IsMatch(inputEmail);
}