Results 1 to 6 of 6

Thread: How to check for character?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68

    How to check for character?

    Hello, i need to check the character whcich the user input. For eg: I got email add, then need them to enter the full address of the email, then i need to check where the @ sign exists.
    So how do i check? Can pls give mi some codes, i need this urgently. Thanks all the kind souls out there, hav a nice day...

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you mean this? ...
    VB Code:
    1. [COLOR=blue]If Not[/COLOR] TextBox1.Text.IndexOf("@") = -1 [COLOR=blue]Then[/color]
    2.             [COLOR=blue]Dim[/color] x [COLOR=blue]As Integer[/color] = TextBox1.Text.IndexOf("@")
    3.             MessageBox.Show("the textbox contains the @ sign at char posistion : " & x)
    4.         [COLOR=blue]End If[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    Sorrie, no, i mean is i need to check whether the user enter email add in the text box got the @ sign anot. If not, then need to prompt them error, if got, then save into the database.

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    the above code does check to see if there's an @ symbol , all you need is to make it suit your needs , eg:
    VB Code:
    1. [color=blue]If Not[/color] TextBox1.Text.IndexOf("@") = -1 [color=blue]Then[/color] [color=green]'/// if the string contains the @ symbol[/color]
    2.             [color=green]'/// carry out your code for the string because it contains an email address.[/color]
    3.         [color=blue]Else[/color] [color=green]'/// if it doesn't contain the @ symbol...[/color]
    4.             MessageBox.Show("you did not type a valid email address, please try again!")
    5.         [color=blue]End If[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2003
    Posts
    68
    Oh, it works. Thanks a lot.
    So how about checking for like not more than 1 @ sign?
    Then how to check e email should be .com/.gov/.edu... etc behind?

  6. #6
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    like this then ...
    VB Code:
    1. [COLOR=BLUE]If[/COLOR] [COLOR=BLUE]Not[/COLOR] TextBox1.Text.IndexOf("@") = -1 [COLOR=BLUE]Then
    2. [/COLOR]            [COLOR=BLUE]Dim[/COLOR] x [COLOR=BLUE]As[/COLOR] [COLOR=BLUE]Integer[/COLOR] = [color=black]UBound[/color](TextBox1.Text.[color=black]Split[/color]("@"c))
    3.             [COLOR=BLUE]If[/COLOR] x = 1 [COLOR=BLUE]Then
    4. [/COLOR]                [COLOR=BLUE]If[/COLOR] TextBox1.Text.EndsWith(".com".ToLower) [COLOR=BLUE]Or[/COLOR] TextBox1.Text.EndsWith(".net".ToLower) [COLOR=BLUE]Or[/COLOR] TextBox1.Text.EndsWith(".gov".ToLower) [COLOR=BLUE]Then
    5. [/COLOR]                    [COLOR=GREEN]'/// it ends with .com or .net or .gov ( etc... depending what you want to look for at the end of the address )
    6. [/COLOR]                    [COLOR=GREEN]'/// do your stuff here because it's a valid address...
    7. [/COLOR]                [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
    8. [/COLOR]            [COLOR=BLUE]Else
    9. [/COLOR]                [COLOR=GREEN]'/// it's got more than 1 @ symbol.
    10. [/COLOR]                MessageBox.Show("to many @ symbols in the address!")
    11.             [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If
    12. [/COLOR]        [COLOR=BLUE]Else
    13. [/COLOR]            MessageBox.Show("Oops that's not a valid email address!")
    14.         [COLOR=BLUE]End[/COLOR] [COLOR=BLUE]If[/COLOR]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width