Pattern Matching in C#
-
I want to have a textbox in which the user can enter only nos. In vb.net we can match the pattern by using the like operator followe by the preferences (e.keyChar Like "[0-9.]"). But how can i do it in C# Plz give me a hint.
Best Regards, M. J. Jaya Chitra
-
I want to have a textbox in which the user can enter only nos. In vb.net we can match the pattern by using the like operator followe by the preferences (e.keyChar Like "[0-9.]"). But how can i do it in C# Plz give me a hint.
Best Regards, M. J. Jaya Chitra
You can use a maskedtextbox, or use regex, or use char.IsDigit, etc, in a key pressed event handler. e.KeyCar LIKE "[0-9.]" is doing a regex pattern match, which is wasteful compared to char.IsDigit, but with different syntax, it works fine in C#.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
You can use a maskedtextbox, or use regex, or use char.IsDigit, etc, in a key pressed event handler. e.KeyCar LIKE "[0-9.]" is doing a regex pattern match, which is wasteful compared to char.IsDigit, but with different syntax, it works fine in C#.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
How about using RegularExpressionValidator control of C#? -- modified at 4:25 Tuesday 5th June, 2007
Regards, Murali
That does something entirely different, a regular expression validator tells you if your input was formatted correctly. He wants the control to not allow invalid input.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
That does something entirely different, a regular expression validator tells you if your input was formatted correctly. He wants the control to not allow invalid input.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
I have to allow only the nos so I tried by checking the keyvalue so it is checking fine but it should not be allowed to be in the textbox know but whenever i am setting e.keyvalue=0, it is giving that it is a read only property, so plz give me a hint how to disable the invalid characters and to allow only nos and .(dot).
Best Regards, M. J. Jaya Chitra
-
I have to allow only the nos so I tried by checking the keyvalue so it is checking fine but it should not be allowed to be in the textbox know but whenever i am setting e.keyvalue=0, it is giving that it is a read only property, so plz give me a hint how to disable the invalid characters and to allow only nos and .(dot).
Best Regards, M. J. Jaya Chitra
if (!char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; } Something like that. setting handled to true stops the base class from handling the key press ( so it is then ignored )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
if (!char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; } Something like that. setting handled to true stops the base class from handling the key press ( so it is then ignored )
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Thank you so much it is working well and good. Once again Thank you
Best Regards, M. J. Jaya Chitra