コード例 #1
0
 /// <summary>
 /// handle the textbox for typing only digit
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void txtKeyPress_KeyPress(object sender, KeyPressEventArgs e)
 {
     YKNumericUtilities.KeyPressEvent(e);
 }
コード例 #2
0
        /// <summary>
        /// validate all inputs correct and reformat if it is not right format
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (YKNumericUtilities.IsNumeric(txtNumeric.Text))
            {
                lblNumericResult.Text = "Inputed String is Numeric";
            }
            else
            {
                lblNumericResult.Text = "Inputed String is not Numeric";
            }

            if (YKNumericUtilities.IsInteger(txtInteger.Text))
            {
                lblIntegerResult.Text = "Inputed String is Integer";
            }
            else
            {
                lblIntegerResult.Text = "Inputed String is not Integer";
            }

            string result = "";

            result = YKNumericUtilities.MakeNumber(txtMakeNumbers.Text);
            if (result == null)
            {
                lblMakeNumbersResult.Text = "Making Numbers is failed";
            }
            else
            {
                lblMakeNumbersResult.Text = result.ToString();
            }

            lblNameResult.Text = YKStringUtilities.Capitalize(txtName.Text);

            lblAddressResult.Text = YKStringUtilities.Capitalize(txtAddress.Text);

            lblCityResult.Text = YKStringUtilities.Capitalize(txtCity.Text);

            if (YKValidations.ValidatePhoneNumber(txtPhoneNumber.Text))
            {
                lblPhoneNumberValid.Text = "Phone number is valid";

                lblPhoneNumberResult.Text = YKStringUtilities.FormatPhoneNumber(txtPhoneNumber.Text);
            }
            else
            {
                lblPhoneNumberValid.Text = "Phone number is not valid";
            }


            if (YKValidations.ValidateCanadianPostalCode(txtPostalCode.Text))
            {
                lblPostalCodeValid.Text = "Postcal Code is valid";

                lblPostalCodeResult.Text = YKStringUtilities.FormatCanadianPostalCode(txtPostalCode.Text);
            }
            else
            {
                lblPostalCodeValid.Text = "Postcal Code is not valid";
            }

            if (YKValidations.ValidateUPZipCode(txtUSPostalCode.Text))
            {
                lblUSPostalCodeValid.Text = "US Postcal Code is valid";

                lblUSPostalCodeResult.Text = YKStringUtilities.FormatUSZipCode(txtUSPostalCode.Text);
            }
            else
            {
                lblUSPostalCodeValid.Text = "US Postcal Code is not valid";
            }

            lblFullNameResult.Text = YKStringUtilities.MakeFullName(txtFirstName.Text, txtLastName.Text);
        }
コード例 #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            string errorMessage = "";

            /*
             * YKFullName(string1, string2) return string
             *  combine firstname and lastname then makes it to full name format
             */
            txtFullName.Text = YKStringUtilities.YKFullName
                                   (txtFirstName.Text, txtLastName.Text);
            if (txtFullName.Text == "")
            {
                errorMessage += "Please input FirstName, LastName or Both\n";
            }

            /*
             * IsInteger(string) return bool
             *  Check the string is Integer or not, by regex
             *
             * IsInteger(int) return bool
             *  Check the string is Integer or not, by regex
             */

            if (rbtInt.Checked)
            {
                int age;
                if (int.TryParse(txtAge.Text, out age))
                {
                    if (!YKNumericUtilities.IsInteger(age))
                    {
                        errorMessage += "Age is Invalid\n";
                    }
                }
                else if (!YKNumericUtilities.IsInteger(txtAge.Text))
                {
                    errorMessage += "Age is Invalid\n";
                }
            }
            else if (rbtString.Checked)
            {
                if (!YKNumericUtilities.IsInteger(txtAge.Text))
                {
                    errorMessage += "Age is Invalid\n";
                }
            }
            else
            {
                errorMessage += "Choose the radio button for Age DataType\n";
            }


            /*
             *  YKCanadaPostal(string) return bool
             *      Check the string is CanadaPostal Code format or not, by regex
             *
             *  YKFormatPostal(string) return string
             *      Reformat string to CanadaPostal Code format.
             */
            if (!YKValidations.YKCanadaPostal(txtCanadaPostal.Text))
            {
                errorMessage += "Canada Postal Code is Invalid\n";
            }
            else
            {
                lblCanadaPostal_result.Text = YKStringUtilities.YKFormatPostal
                                                  (txtCanadaPostal.Text);
            }


            /*YKUSPostal(string) return bool
             *  Extract digits by YKOnlyDigits then chech the length is 5 or 9
             *
             * YKOnlyDigits(string) return string
             *  Extract digits from string*/
            if (!YKValidations.YKUSPostal(txtUSPostal.Text))
            {
                errorMessage += "US Postal Code is Invalid\n";
            }
            else
            {
                lblUSPostal_result.Text = YKStringUtilities.YKOnlyDigits
                                              (txtUSPostal.Text);
                lblUSPostal_result.Text = YKStringUtilities.YKReFormat
                                              (lblUSPostal_result.Text);
            }


            /*YKPhoneNumber(string) return bool
             *  Extract digits by YKOnlyDigits then chech the length is 10 or not
             *
             * YKOnlyDigits(string) return string
             *  Extract digits from string
             *
             * YKReFormat(string) return string
             *  if the string is length of 10, reformat it to PhoneNumber format*/
            if (!YKValidations.YKPhoneNumber(txtPhoneNumber.Text))
            {
                errorMessage += "Phone Number is Invalid\n";
            }
            else
            {
                lblPhoneNumber_result.Text = YKStringUtilities.YKOnlyDigits
                                                 (txtPhoneNumber.Text);
                lblPhoneNumber_result.Text = YKStringUtilities.YKReFormat
                                                 (txtPhoneNumber.Text);
            }


            /*Print ERROR MESSAGE when the errorMessage is not empty*/
            if (errorMessage == "")
            {
                lblError.Text = "Successfully Submitted!\n";
            }
            else
            {
                lblError.Text = errorMessage;
            }
        }