G
Guest
Hi,
I have to validate TextBox.
I have a customValidate control for textbox. I have following function for
customValidate control.
but if I type in textbox bobby
It throws exception that index shouldnot be less than zero
but if I type (e-mail address removed)(bobby gill). It works. I want that if I if I
type bobby the validation control gives me error that it is not valid
public void ValidateUserID(object sender, ServerValidateEventArgs args)
{
CustomValidator valDate = sender as CustomValidator;
args.IsValid = true;
string str = args.Value;
//string str = this.txtAddUsers.Text;
string subStr1 = str.Substring(0, str.IndexOf("( "));
bool isValidEmail = IsValidEmail(subStr1);
if (isValidEmail == true)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
valDate.ErrorMessage = "Email is Invalid!";
return;
}
}
public static bool IsValidEmail(string EmailAddress)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(EmailAddress,
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
I have to validate TextBox.
I have a customValidate control for textbox. I have following function for
customValidate control.
but if I type in textbox bobby
It throws exception that index shouldnot be less than zero
but if I type (e-mail address removed)(bobby gill). It works. I want that if I if I
type bobby the validation control gives me error that it is not valid
public void ValidateUserID(object sender, ServerValidateEventArgs args)
{
CustomValidator valDate = sender as CustomValidator;
args.IsValid = true;
string str = args.Value;
//string str = this.txtAddUsers.Text;
string subStr1 = str.Substring(0, str.IndexOf("( "));
bool isValidEmail = IsValidEmail(subStr1);
if (isValidEmail == true)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
valDate.ErrorMessage = "Email is Invalid!";
return;
}
}
public static bool IsValidEmail(string EmailAddress)
{
// Return true if strIn is in valid e-mail format.
return Regex.IsMatch(EmailAddress,
@"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");