Prev: Problem handling keyboard events in ActiveX on IE8
Next: project dependencies: satellite dlls and main-project
From: Cameron_C on 23 Jun 2010 12:30 Everyone, thanks for the feedback. What I really "needed" to hear was that performance should only be factored in, if I am considering a heavy weight implementation of the Regex facilities. To clarify thiings a bit, I only want to edit a few input fields in a dialog. Maybe fifteen or twenty in a window. I want to ensure proper formatting of telephone numbers (999-999-9999), Canadian Postal Codes (A9A 9A9), and dollar amount fields ($99999.99). If the fields do not appear to be formatted correctly, I pop up an error message. I realize this is small stuff in the overall scheme of things. Maybe I am being lazy here. It seemed to me to be a perfect fit for the Regex functionality. "Cameron_C" wrote: > Hello again folks, > I am working through things in my application, and I would appreciate any > recommended approaches to using Regular Expressions in my code. > This is an MFC application. I am using Visual Studio 2008 pro. > I have read about references to a "boost" library, and I have read > references to an ATL regex class, and I have read something about Regular > Expressions being included in SP1 of VS2008. > I wnat to use regular expressions to edit telephone numbers, and Postal > Codes, and dollar amount fields. > > Anyway, if anyone has any experience with any of the above, and can offer > some advice or recommendation, I would appreciate it. >
From: Pete Delgado on 23 Jun 2010 12:55 "Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message news:671FE8FD-E3B0-492F-AAF0-B6136F0BC42A(a)microsoft.com... > Everyone, thanks for the feedback. > What I really "needed" to hear was that performance should only be > factored > in, if I am considering a heavy weight implementation of the Regex > facilities. > To clarify thiings a bit, I only want to edit a few input fields in a > dialog. Maybe fifteen or twenty in a window. > I want to ensure proper formatting of telephone numbers (999-999-9999), > Canadian Postal Codes (A9A 9A9), and dollar amount fields ($99999.99). If > the > fields do not appear to be formatted correctly, I pop up an error message. > I realize this is small stuff in the overall scheme of things. > Maybe I am being lazy here. It seemed to me to be a perfect fit for the > Regex functionality. That is a perfectly legitimate use of regular expressions. I think what most people were simply saying was that you should not let percieved performance guide your decision on *which* library to use because it was unlikely that you were using the library heavily enough to make performance an issue.Your problem description shows that this was indeed the case. If your purpose is to validate input fields on a form, assuming that you are taking into account I8N issues, perhaps custom controls for the fields would be appropriate. If you perform validation at the control level, you can design the controls in such a way as to eliminate error message popups because the controls will only accept valid inputs. Joe has an example of a validating edit control on his site and there are many others out there as well. Here's a link to Joe's example and one that is on MSDN. http://www.flounder.com/validating_edit_control.htm http://msdn.microsoft.com/en-us/magazine/cc300635.aspx -Pete
From: Joseph M. Newcomer on 23 Jun 2010 14:15 See my Validating Edit Control on my MVP Tips site. I consider the "pop up a dialog box if the field is invalid" to be one of the worst human interfaces ever conceived. I believe in "real-time" validation, and the OK button is not even *enabled* if every control doesn't have valid data in it. I first developed the edit control for a client who had a highly-stylized part number, sort of along the lines of ABC-1234X where there were three letters, a hyphen, 3 or 4 digits, and a possible letter following (which turned out to be a color designator). When I delivered it, a number of data entry people complained about the changing colors, and asked that they be removed. So I did. And all the *rest* of the data entry people complained that this incredibly useful feature had been removed! So we made it a user-selectable option. What I did was do validation every time I got an EN_CHANGE notification, by parsing the text. If it parsed as valid, the background went (very light) green. If it was syntactically illegal, the background went (very light) red. If the input was incomplete, the background went (very light) yellow. If data is invalid and the OK button is enabled, I consider that the dialog is defective in its basic design. I've used a number of techniques to handle validation. In addition to the validating edit control changing colors, I've used tooltips over the control to tell why ("incomplete part number" and several variants of this; "invalid part number" complete with an explanation), using a CStatic which is normally invisible but if there is an error displays the error text with yellow letters on a red background, and having a tooltip display if you hover over the (disabled) OK button. In one complex dialog, a listbox would appear listing every error in every control. Never do validation in the OnKillFocus handler. This is bad taste, and will lead to a real nightmare. For example, if you try to pop up a dialog box in an OnKillFocus handler, you are in very deep trouble (it used to just lock up the entire app! I don't know if this has been fixed). Dialog boxes to report errors are SO 1980s! Users won't tell you this unless you ask them, but they find them offensive. Note that a regexp can give you are "correct" or "not correct" result, but not an "incomplete" result. Fortunately, the cases you are describing are truly trivial variants of my validating edit control, and what I would do is rip out the floating-point validation code from my example and use a virtual method, then subclass the dialogs for "SSN", "Dollars", and so on, and put the validating code in the overridden virtual method of each subclass. Alternatively, you can used a "masked edit control" from a third-party vendor; in these controls, if you type the first three digits of an SSN, it inserts the hyphen for you. Don't Try This At Home. They are not easy to write (I've done a couple, and consider them not worth the effort to re-create from scratch, when you can buy them cheaper) Given how trivial the validation code is, I'd consider a regexp to be overkill for technology and also inadequate because it can't tell partially-correct results joe On Wed, 23 Jun 2010 09:30:40 -0700, Cameron_C <CameronC(a)discussions.microsoft.com> wrote: > >Everyone, thanks for the feedback. >What I really "needed" to hear was that performance should only be factored >in, if I am considering a heavy weight implementation of the Regex facilities. >To clarify thiings a bit, I only want to edit a few input fields in a >dialog. Maybe fifteen or twenty in a window. >I want to ensure proper formatting of telephone numbers (999-999-9999), >Canadian Postal Codes (A9A 9A9), and dollar amount fields ($99999.99). If the >fields do not appear to be formatted correctly, I pop up an error message. >I realize this is small stuff in the overall scheme of things. >Maybe I am being lazy here. It seemed to me to be a perfect fit for the >Regex functionality. > >"Cameron_C" wrote: > >> Hello again folks, >> I am working through things in my application, and I would appreciate any >> recommended approaches to using Regular Expressions in my code. >> This is an MFC application. I am using Visual Studio 2008 pro. >> I have read about references to a "boost" library, and I have read >> references to an ATL regex class, and I have read something about Regular >> Expressions being included in SP1 of VS2008. >> I wnat to use regular expressions to edit telephone numbers, and Postal >> Codes, and dollar amount fields. >> >> Anyway, if anyone has any experience with any of the above, and can offer >> some advice or recommendation, I would appreciate it. >> Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on 23 Jun 2010 14:17 But it is so trivial to write an FSM parser; for the cases cited, I can write an FSM parser as fast as I can type. A regexp is technological overkill, particularly because the flexibility of a programmable pattern is not required! joe On Wed, 23 Jun 2010 12:55:32 -0400, "Pete Delgado" <Peter.Delgado(a)NoSpam.com> wrote: > >"Cameron_C" <CameronC(a)discussions.microsoft.com> wrote in message >news:671FE8FD-E3B0-492F-AAF0-B6136F0BC42A(a)microsoft.com... >> Everyone, thanks for the feedback. >> What I really "needed" to hear was that performance should only be >> factored >> in, if I am considering a heavy weight implementation of the Regex >> facilities. >> To clarify thiings a bit, I only want to edit a few input fields in a >> dialog. Maybe fifteen or twenty in a window. >> I want to ensure proper formatting of telephone numbers (999-999-9999), >> Canadian Postal Codes (A9A 9A9), and dollar amount fields ($99999.99). If >> the >> fields do not appear to be formatted correctly, I pop up an error message. >> I realize this is small stuff in the overall scheme of things. >> Maybe I am being lazy here. It seemed to me to be a perfect fit for the >> Regex functionality. > >That is a perfectly legitimate use of regular expressions. I think what most >people were simply saying was that you should not let percieved performance >guide your decision on *which* library to use because it was unlikely that >you were using the library heavily enough to make performance an issue.Your >problem description shows that this was indeed the case. > >If your purpose is to validate input fields on a form, assuming that you are >taking into account I8N issues, perhaps custom controls for the fields would >be appropriate. If you perform validation at the control level, you can >design the controls in such a way as to eliminate error message popups >because the controls will only accept valid inputs. > >Joe has an example of a validating edit control on his site and there are >many others out there as well. Here's a link to Joe's example and one that >is on MSDN. > >http://www.flounder.com/validating_edit_control.htm >http://msdn.microsoft.com/en-us/magazine/cc300635.aspx > > > >-Pete > > > Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Pete Delgado on 23 Jun 2010 15:25 "Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message news:cqj426tf8a7iiggmrdv3boe0u6043uuiio(a)4ax.com... > But it is so trivial to write an FSM parser; for the cases cited, I can > write an FSM > parser as fast as I can type. A regexp is technological overkill, > particularly because > the flexibility of a programmable pattern is not required! > joe Joe, If you take into account internationalization and the differences in format pattern required for the fields cited, the FSM approach becomes more complex than using one of the regular expression libraries. Of course, I'm assuming that the author is familiar with writing validating regular expressions because it is just as easy to write a buggy expression as it is to write buggy code! However, if this particular piece of code will *never* be used anywhere else except where the author intends, then I see the wisdom in your approach and completely agree with your conclusion that a regexp is overkill and cannot handle incomplete data cases while your method can. -Pete
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Problem handling keyboard events in ActiveX on IE8 Next: project dependencies: satellite dlls and main-project |