Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / September 2007

Tip: Looking for answers? Try searching our database.

email validation

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bobby - 14 Sep 2007 01:46 GMT
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 bobby@yahoo.com(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})(\]?)$");
Siva M - 14 Sep 2007 03:20 GMT
"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.

> Hi,
>
[quoted text clipped - 34 lines]
>             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})(\]?)$");

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.