 
     else # create a subdomain
       subDomainPattern = /^([a-z0-9]([_\-](?![_\-])|[a-z0-9]){0,60}[a-z0-9]|[a-z0-9])$/
-      unless subDomainPattern.test domain
+      unless subDomainPattern.test domainName
         createButton.hideLoader()
         return notifyUser "#{domainName} is an invalid subdomain."
-      domain = "#{domainName}.#{domains.getValue()}"
-
-      @createDomain {domain, regYears:0, domainType:'subdomain'}, (err, domain)=>
+      domainName = "#{domainName}.#{domains.getValue()}"
+
+      @createDomain {domainName, regYears:0, domainType:'subdomain'}, (err, domain)=>
         createButton.hideLoader()
         if err
           warn err

    {createButton, registerButton} = form.buttons
    @clearSuggestions()

    {DomainOption, domainName, regYears, domains, extensionSelect} = form.inputs
    domainInput       = domainName
    domain            = domainName.getValue()
    tld               = extensionSelect.getValue()
    unless domain.match(/^\w+$/)
      notifyUser "Please select the extension from the select box"
      registerButton.hideLoader()
      return
    domainOptionValue = DomainOption.getValue()

    if domainOptionValue is 'new'
        form = @forms["Domain Address"]
        {createButton, registerButton} = form.buttons
        paymentController = KD.getSingleton('paymentController')
        group             = KD.getSingleton("groupsController").getCurrentGroup()
        registerTheDomain = ->
            KD.remote.api.JDomain.registerDomain
              domainName : domainInput.getValue()
              years      : regYears.getValue()
            , (err, domain) =>
              if err
                warn err
                console.log err
                notifyUser "An error occured. Please try again later."
              else
                @showSuccess domain
                domain.setDomainCNameToProxyDomain()
              registerButton.hideLoader()

        paymentController.getBillingInfo 'user', group, (err, account)->
          need = err or not account or not account.cardNumber
          if need
            paymentController.setBillingInfo 'user', group, (success)->
              if success
                registerTheDomain()
          else
            registerTheDomain()


    else if domainOptionValue is 'existing'
      @createDomain {domain, regYears:0, domainType:'existing'}, (err, domain)=>
        createButton.hideLoader()
        if err
          warn err

                    @suggestionBox?.hide()
                    # domainName.setValidation domainNameValidation
                    domains.hide()
                    regYears.hide()
                    checkButton.hide()
                    registerButton.hide()
