Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. validation

validation

Scheduled Pinned Locked Moved C#
comquestion
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abu rakan
    wrote on last edited by
    #1

    hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that

    M C 2 Replies Last reply
    0
    • A abu rakan

      hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #2

      well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character. something like:

      string text = TextBox1.Text;

      string[] split = text.split('@');

      if(split.length == 1)//only one '@' character
      {
      if(split[1].Contains('.'))
      //Could be a valid email
      }
      //else is not a valid email address

      M 1 Reply Last reply
      0
      • M musefan

        well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character. something like:

        string text = TextBox1.Text;

        string[] split = text.split('@');

        if(split.length == 1)//only one '@' character
        {
        if(split[1].Contains('.'))
        //Could be a valid email
        }
        //else is not a valid email address

        M Offline
        M Offline
        Manas Bhardwaj
        wrote on last edited by
        #3

        musefan wrote:

        well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.

        Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.

        Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

        M B 2 Replies Last reply
        0
        • A abu rakan

          hi men how can I make validation to accept specific input such as in my text box Only email is valid input aaa..@dddd.com like that

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          abu rakan wrote:

          hi men

          There are women on this site, too. There's a control built in for validating text, or, as someone said, you can use regex.

          Christian Graus Driven to the arms of OSX by Vista.

          A 1 Reply Last reply
          0
          • M Manas Bhardwaj

            musefan wrote:

            well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.

            Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            I have, but I dont remember how to do off top of head so offered another solution

            1 Reply Last reply
            0
            • C Christian Graus

              abu rakan wrote:

              hi men

              There are women on this site, too. There's a control built in for validating text, or, as someone said, you can use regex.

              Christian Graus Driven to the arms of OSX by Vista.

              A Offline
              A Offline
              abu rakan
              wrote on last edited by
              #6

              I am soooooo sorry "Christian Graus" about hi men about my problem actually i don't understand you or may be you don't understand me!!!!

              K 1 Reply Last reply
              0
              • A abu rakan

                I am soooooo sorry "Christian Graus" about hi men about my problem actually i don't understand you or may be you don't understand me!!!!

                K Offline
                K Offline
                Kaushal Arora
                wrote on last edited by
                #7

                This is a javascript email validator. This validator can be customized to allow any domain name.

                */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy
                cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse

                1 Reply Last reply
                0
                • M Manas Bhardwaj

                  musefan wrote:

                  well one option would be to check for a '@' character in the textbox.Text string, then see if there is atleast one '.' character after the '@' character.

                  Have you ever heard of Regular Expressions? In fact, Regular Expression validators(as the name suggest) can do this with lot ease.

                  Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                  B Offline
                  B Offline
                  butchzn
                  wrote on last edited by
                  #8

                  <asp:TextBox ID="tbEmail" runat="server" ValidationGroup="Register" />

                  <asp:RegularExpressionValidator ForeColor="Red" ValidationGroup="Register" ControlToValidate="tbEmail" ErrorMessage="Email Address is not valid." ValidationExpression="^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$" EnableClientScript="true" ID="RegularExpressionValidator1" runat="server" Display="Dynamic" />

                  Or you could create a custom validator that will do the validation for you and set your page IsValid property to true or false depending whether valid or not.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups