 |
|
 |
An excellent control. Can you make a pure Win32 C version (without MFC)?
|
|
|
|
 |
|
 |
Unfortunately too many programmers do input validation as an afterthought, if they think about it at all. Also not enough programmers are familiar with RegEx.
So cudos for a well written and useful article.
Just because the code works, it doesn't mean that it is good code.
|
|
|
|
 |
|
 |
Thank You for doing this job!
I wanted to use decimal “,” (Komma) instate decimal “.”
How can I do this in “CFloatEdit”? Safe it in a float Value and load it form.
Peet
|
|
|
|
 |
|
 |
I have posted a new version to Code Project:
void CFloatEdit::CreateRegexes(const unsigned int uiWhole)
{
TCHAR szSeparator[4] = _T("");
CString strSeparator;
CString strSignedRegEx;
CString strUnsignedRegEx;
::GetLocaleInfo (LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szSeparator, 4);
strSeparator = szSeparator;
EscapeString(strSeparator);
strSignedRegEx.Format(_T("[-+]?([0-9]{1,%d}(%s[0-9]{0,2})?")
_T("|%s[0-9]{1,2})"), uiWhole, strSeparator, strSeparator);
strUnsignedRegEx.Format(_T("([0-9]{1,%d}(%s[0-9]{0,2})?")
_T("|%s[0-9]{1,2})"), uiWhole, strSeparator, strSeparator);
m_SignedRegEx.assign (strSignedRegEx);
m_UnsignedRegEx.assign (strUnsignedRegEx);
}
Note that EscapeString() needs to be made static in CBaseEdit now for this to work.
|
|
|
|
 |
|
|
 |
|
 |
I have done that too last year with MFC and Boost-Regex. Although your code save a lot of time, I must say that I learned a lot more doing it myself.
|
|
|
|
 |
|
 |
I originally had the idea in 1995, but in those days there wasn't a reliable regex library I could use! It took me many years to write my own, by which time boost::regex was available...
Cheers,
Ben
|
|
|
|
 |
|
 |
We're all getting old, what a shame.
But why didn't you take for example the Regex code from Perl?
|
|
|
|
 |
|
 |
The short answer is that I favoured a C++ solution (exception safety blah, blah, blah...) Of course boost::regex provides this and incidentally so does lexertl (http://www.benhanson.net/lexertl.html[^]).
|
|
|
|
 |
|
 |
Thank You for doing this job! Quite the thing for a long time!
|
|
|
|
 |
|
|
 |
|
 |
Well explained. You saved a lot of people a lot of time re-inventing the wheel. Thanks for sharing. And I like that C and MFC is still supported!
|
|
|
|
 |
|
|
 |
|
 |
I am trying to determine how to use FloatEdit to validate a string from a dialog as a float or double value. First, in FloatEdit.cpp I notice the function:
double CFloatEdit::GetValue () const
Let see, GetValue(), that means go and get/ retrieve something from somewhere. But there is no argument to specify the source of the data. Rather than being a straight forward function, it must rely on what is called a side effect. So we check into the function and look for that side effect.
I find function:
GetWindowText (strFloat);
Another function that gets (that is to say, retrieves) something, expectedly text. But what is the source of the data retrieved. The name of the argument indicates a string. But a string is what I want it to get. Now I see that StrFloat is declared locally so GetWindowText must get the string from somewhere. Where? How does it know where to get the text.
Search for GetWindowText. Not found. Go to the boot library that I installed in C:/Program Files\boost. Not found.
Go to windows help function and loop up GetWindowText:
int GetWindowText( HWND hWnd,
LPTSTR lpString,
int nMaxCount );
Hmmm, not the same function. There appears to be insufficient information to determine how this works.
So, describe my need and maybe someone will give me a clue:
One of the fields if my dialog that I want filtered is an edit control box and has the ID:
IDC_X_POSITION_EDIT
and strings in the box can be accessed via a variable name as follows:
GBE_x_position_string.GetWindowTextW( str );
That puts the value into CString names str. This does indeed provide the string from the dialog box.
Will someone tell me how to use this FloatEdit to:
1. verify that the text in this dialog box text field is valid for a float or double, and
2. How put that value into a double variable?
Thanks for your time
|
|
|
|
 |
|
 |
1. Call IsInputValid() on CFloatEdit.
2. double d = GBE_x_position_string.GetValue();
Try looking up CWnd in the help and searching for GetWindowText() there. You should also read something on object oriented programming.
Regards,
Ben
|
|
|
|
 |
|
 |
I downloaded the CFilterEdit code and demoproject.
File BaseEdit.h contains this line:
#include
This file in not contained in the download. This is the only file containing the include and it has no previous includes that lead me to the file.
Where do I find this file?
Thanks for your time
|
|
|
|
 |
|
 |
I assume you are looking for boost/regex.hpp.
You can find the boost library at www.boost.org.
For instructions on compiling the regex library, see
[^]
(Note that the latest version 1.35.0, so change the paths accordingly)
Regards,
Ben
|
|
|
|
 |
|
 |
Kirk: Do you suppose if you continue to beat it.....
McCoy: LET IT DIEEEEEEEEEEEEEEE, Jim
Kirk: Just beat it some more, Bones... Let's see what happens.
McCoy: I'M A DOCTOR NOT A MAGICIAN.
Kirk: But if you just beat it some more, it might still....
|
|
|
|
 |
|
 |
Lay off the cough medicine hombre...
|
|
|
|
 |
|
 |
The horse is dead only when there are no more people interested in it. This is not the case here, partially because WPF was released unfinished and because the C++/CLI syntax to access Windows Forms is not so pleasant. And you may want to control the memory footprint of your application.
|
|
|
|
 |
|
 |
I need to take an existing English application and accept special characters typed from the keyboard like èï, et. The member variable of the dialog is defined as a CString. When I trap the CString the character is properly displayed in debugger but the value is negative. Using iswalpha does not identify it as an alpha character (using isalpha throws exception.) I also need to disallow digits and iswdigit does not work. Where do I go for help?
Thanks.
narlad
|
|
|
|
 |
|
 |
I don't have experience of using iswalpha or iswdigit, but if your characters show negative values then presumably you haven't done a UNICODE build as wchar_t is unsigned?
Ben
|
|
|
|
 |
|
 |
Hello I want to use your class for validating the user input for a correct url.
I found the ultimate regex therefore:
http://foad.org/~abigail/Perl/url2.html
Direct link to regex:
http://foad.org/~abigail/Perl/url3.regex
But how can I use this very long regular expression?
The line:
CString strRegEx (_T("THE_REGEX_FROM_SITE_WITHOUT_NEWLINE"));
don't work, perhaps too long?
Thanks!
|
|
|
|
 |
|
 |
Did you escape all the '\' characters? Remember it's not enough to just paste a regex into a C++ string, it still has to follow the C++ string rules.
It should be enough to do a find and replace of \ to \\ - at least I can't see anything else you need to change. boost::regex in release 0.34 defaults to PERL compatibility.
Non marking grouping "(?:" is compatible.
OK, let me know how you get on..!
Cheers,
Ben
|
|
|
|
 |
|
 |
Hi Ben,
you are right, I forgot to escape the '\' characters.
But after testing this regular expression for checking of a URL, I think the regex above is not the best.
Do you have a regex therefore which works good (with alternative user and port and so on)?
Do you found a solution to the drawing problem for my last post (manifest problem)?
Cheers
|
|
|
|
 |