This is a migrated thread and some comments may be shown as answers.

textbox and datepicker validation

1 Answer 93 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Laxman
Top achievements
Rank 1
Laxman asked on 01 Aug 2011, 11:48 AM
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;

                }
          
        }


1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 04 Aug 2011, 08:18 AM
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 >>

Tags
General Discussions
Asked by
Laxman
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or