Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > email validation

Reply
Thread Tools

email validation

 
 
=?Utf-8?B?Ym9iYnk=?=
Guest
Posts: n/a
 
      09-14-2007
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 http://www.velocityreviews.com/forums/(E-Mail 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})(\]?)$");

 
Reply With Quote
 
 
 
 
=?Utf-8?B?U2l2YSBN?=
Guest
Posts: n/a
 
      09-14-2007
"bobby" doesn't have '(' in it and so IndexOf returns -1 which cannot be used
in Substring operation. So, assign the return value of IndexOf to a variable,
compare it and then use it for subsequent processing.

"bobby" wrote:

> 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 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})(\]?)$");
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying a Validation Error in a Validation Summary Control Lucas Tam ASP .Net 2 02-26-2004 07:49 PM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM
validation summary doesnt display when there's client-side validation Libs ASP .Net 0 06-25-2003 03:05 PM
Re: only custom validation control does server side validation? Colin Mackay ASP .Net 0 06-25-2003 07:54 AM



Advertisments