コード例 #1
0
        /// <summary>
        /// Determine that the form is valid by checking each input.
        /// </summary>
        /// <returns></returns>
        private Boolean IsValidForm()
        {
            Boolean valid = true;

            // Validate e-mail input.
            if (HString.IsValidEmail(this.txtEmail.Text.Trim()))
            {
                this.AddResultControl(this.inputEmail, this.txtEmail.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputEmail, this.txtEmail.Text.Trim(), false);
                valid = false;
            }

            // Validate password input.
            if (HString.IsValidPassword(this.txtPassword.Text.Trim()))
            {
                this.AddResultControl(this.inputPassword, this.txtPassword.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputPassword, this.txtPassword.Text.Trim(), false);
                valid = false;
            }

            // Validate phone number input.
            if (HString.IsValidPhoneNumber(this.txtTelephoneNo.Text.Trim()))
            {
                this.AddResultControl(this.inputTelephoneNo, this.txtTelephoneNo.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputTelephoneNo, this.txtTelephoneNo.Text.Trim(), false);
                valid = false;
            }

            // Validate URL input.
            if (HString.IsValidURL(this.txtWebsite.Text.Trim()))
            {
                this.AddResultControl(this.inputWebsite, this.txtWebsite.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputWebsite, this.txtWebsite.Text.Trim(), false);
                valid = false;
            }

            // Validate ZIP code input.
            if (HString.IsValidZIPCode(this.txtZipCode.Text.Trim()))
            {
                this.AddResultControl(this.inputZipCode, this.txtZipCode.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputZipCode, this.txtZipCode.Text.Trim(), false);
                valid = false;
            }

            // Validate date input.
            if (HDateTime.IsValidDate(this.txtDate.Text.Trim(), "M/d/yyyy", "MM/dd/yyyy"))
            {
                this.AddResultControl(this.inputDate, this.txtDate.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputDate, this.txtDate.Text.Trim(), false);
                valid = false;
            }

            // Validate DOB input.
            if (HDateTime.IsValidDateOfBirth(this.txtDOB.Text.Trim(), "M/d/yyyy", "MM/dd/yyyy"))
            {
                this.AddResultControl(this.inputDOB, this.txtDOB.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputDOB, this.txtDOB.Text.Trim(), false);
                valid = false;
            }

            // Validate military time input.
            if (HDateTime.IsValidMilitaryTime(this.txtTimeMilitary.Text.Trim()))
            {
                this.AddResultControl(this.inputTimeMilitary, this.txtTimeMilitary.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputTimeMilitary, this.txtTimeMilitary.Text.Trim(), false);
                valid = false;
            }

            // Validate standard time input.
            if (HDateTime.IsValidStandardTime(this.txtTimeStandard.Text.Trim()))
            {
                this.AddResultControl(this.inputTimeStandard, this.txtTimeStandard.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputTimeStandard, this.txtTimeStandard.Text.Trim(), false);
                valid = false;
            }

            // Validate number input.
            if (HNumeric.GetNullableInteger(this.txtNumber.Text.Trim()) != null)
            {
                this.AddResultControl(this.inputNumber, this.txtNumber.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputNumber, this.txtNumber.Text.Trim(), false);
                valid = false;
            }

            // Validate currency input.
            if (HNumeric.GetNullableCurrency(this.txtCurrency.Text.Trim(), CultureInfo.GetCultureInfo("en-US")) != null)
            {
                this.AddResultControl(this.inputCurrency, this.txtCurrency.Text.Trim(), true);
            }
            else
            {
                this.AddResultControl(this.inputCurrency, this.txtCurrency.Text.Trim(), false);
                valid = false;
            }

            return(valid);
        }