subdomain validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CFFAN
    New Member
    • Dec 2008
    • 29

    subdomain validation

    How to validate "subdomain" in atextfiled in coldfusion?
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    What do you mean by a subdomain? Can you explain with an example. Some code might also help.

    Comment

    • CFFAN
      New Member
      • Dec 2008
      • 29

      #3
      these are rules to create Sub-Domain Names
      Sub-Domain Names

      A Sub-Domain Name does not form part of a Registered Domain Name, therefore the rules laid down by the Registrar do not apply.

      The characters you can choose from:

      * A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
      * 1 2 3 4 5 6 7 8 9 0
      * Hyphen (-)
      * An address must begin and end with an alphanumeric character. Punctuation characters must not be placed together
      * Sub-Domain names can contain letters, numbers or hyphens (-), NO spaces or other characters are allowed.
      me have lot fdoubts in tht...is more than 2 Hyphen possible? etc..i have to validate thesein coldfusion

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You can use a regular expression to make the checks in one go. See this link.

        Comment

        • CFFAN
          New Member
          • Dec 2008
          • 29

          #5
          K thanks

          <cfset result = REMatch("/^[a-zA-Z0-9\-]*?$/",arguments.sub domain)>



          i used this code for checking subdomain validation. but always getting empty array....hw can i?

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Why do you have a ? in there? Can you give an example of input (arguments.subd omain)?

            Comment

            • CFFAN
              New Member
              • Dec 2008
              • 29

              #7
              arguments.subdo main is test123

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                The regular expression will not match all the conditions that you specified in an earlier post. For a start, try using a +, e.g.
                Code:
                ^[a-z0-9\-]+$
                Note that REMatch is case-insensitive so there's no need to specify different cases.

                Comment

                • CFFAN
                  New Member
                  • Dec 2008
                  • 29

                  #9
                  ok thanks ..
                  i have to satisy there two condition also
                  *An address must begin and end with an alphanumeric character. Punctuation characters must not be placed together
                  * Sub-Domain names can contain letters, numbers or hyphens (-), NO spaces or other characters are allowed.
                  how can this also possible with ?

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    The second condition is already satisfied. For the first condition, you can add a alphanumeric pattern at the beginning and the end:
                    Code:
                    /^[a-z0-9][a-z0-9\-]+[a-z0-9]$/
                    You'll need to add a bit more to ensure that the hyphen doesn't appear more than once together.

                    Comment

                    • CFFAN
                      New Member
                      • Dec 2008
                      • 29

                      #11
                      <cfscript>
                      result = REMatch("/^[a-z0-9][a-z0-9\-]+[a-z0-9]$/",arguments.Web address);
                      </cfscript>

                      <cfdump var="#result #"> always getting empty array..
                      i test with test,test12t etc ....stil sme probs

                      Comment

                      • CFFAN
                        New Member
                        • Dec 2008
                        • 29

                        #12
                        i remove staring / and eng /.then it works....

                        <cfscript>


                        result = REMatch("^[a-z0-9][a-z0-9\-]+[a-z0-9]$",arguments.We baddress);
                        </cfscript>


                        how to avoid continous repetaion of hyphn?

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          There are a number of ways, e.g.
                          Code:
                          ^\w+(\-?\w)*\w+$
                          Note: \w is an escape sequence for alphanumeric characters. You could also use [:alnum:] (a character class).

                          Comment

                          • CFFAN
                            New Member
                            • Dec 2008
                            • 29

                            #14
                            Now it workg fine...ok thank u very muchhhh

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              You're welcome. Glad it's working :)

                              Comment

                              Working...