textbox and datepicker validation

2 posts, 0 answers
  1. Laxman
    Laxman avatar
    6 posts
    Member since:
    Jul 2011

    Posted 01 Aug 2011 Link to this post

    Hi Friends ,

    I am doing validation on textbox
    1) such as Do not allow to enter special character
    2) only allow character & int
    3) allow integer number only
    4) select date from datepicker only. do not allow to enter from keyboard.

    I am done using regex  as well as with code . it show me message for perticular validation but typed key show in textbox

    here is my code

     private void checkvalidation(string Datatype, string txtBoxValue,string txtBoxName)
            {
                    switch (Datatype.ToString().ToLower())
                    {
                        case "system.string":
                            var StringRegexExp = new Regex("^[a-zA-Z0-9 -()@,.]*$");
                            if (!Regex.IsMatch(txtBoxValue, "^[a-zA-Z0-9 -()@,.]*$"))
                                MessageBox.Show("Please do not enter special character.", "Validation", MessageBoxButton.OK);
                                if (txtBoxValue.Length > 0)
                                    txtBoxValue.Remove(txtBoxValue.Length - 1);
                            break;

                        case "system.int32":
                            var IntegexExp = new Regex("^[0-9]+$");
                            if (!Regex.IsMatch(txtBoxValue, "^[0-9]+$"))
                                MessageBox.Show("Please enter numeric values.", "Validation", MessageBoxButton.OK);
                            break;

                        case "datePicker":
                            var DatepickerRegexExp = new Regex("^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)[0-9][0-9]$");
                            if (!Regex.IsMatch(txtBoxValue, "^(0?[1-9]|[12][0-9]|3[01])[- /.](0?[1-9]|1[012])[- /.](19|20)[0-9][0-9]$"))
                                MessageBox.Show("Please select date from datepicker.", "Validation", MessageBoxButton.OK);
                            break;

                    }
              
            }


  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 04 Aug 2011 Link to this post

    Hi Laxman,

    I am not sure if I understand your scenario correctly but I believe that you can take advantage of the RadMaskedInput suite of controls. They support validation out-of-the-box. You can examine this demo for more info or take a look at the online documentation articles on data annotations validation and regex validation. Also, the RadMaskedInput controls expose a ValueChanging() event which can be handled thus preventing the user from entering improper data.

    Finally from you description I couldn't understand if you are using the RadDateTimePicker control and whether you have any issues with it, but if you do please elaborate on those. Thank you in advance.

    Best wishes,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top