wxTextValidator and Filter range Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MuhammadSohail
Experienced Solver
Experienced Solver
Posts: 96
Joined: Fri Jun 17, 2005 1:53 pm
Location: Germany
Contact:

wxTextValidator and Filter range

Post by MuhammadSohail » Wed Jul 22, 2009 8:44 am

Hallo all,
Is there any possibility to define a filter with specific range?

e.g.
I only want to filter following chracters for my password in the wxTextCtrl

A - Z
a - z
0 - 9

MuhammadSohail
Experienced Solver
Experienced Solver
Posts: 96
Joined: Fri Jun 17, 2005 1:53 pm
Location: Germany
Contact:

Post by MuhammadSohail » Thu Jul 30, 2009 10:41 am

Code: Select all

wxArrayString includeList;
	for (size_t i = 65; i <= 90 ; i++)
	{
		std::stringstream alpha;
		alpha << (char) i;
		includeList.Add( wxT(alpha.str()) );
	}
	for (size_t i = 97; i <= 122 ; i++)
	{
		std::stringstream alpha;
		alpha << (char) i;
		includeList.Add( wxT( alpha.str()) );
	}
	includeList.Add(wxT("0"));
	includeList.Add(wxT("1"));
	includeList.Add(wxT("2"));
	includeList.Add(wxT("3"));
	includeList.Add(wxT("4"));
	includeList.Add(wxT("5"));
	includeList.Add(wxT("6"));
	includeList.Add(wxT("7"));
	includeList.Add(wxT("8"));
	includeList.Add(wxT("9"));

wxTextValidator  validator(wxFILTER_INCLUDE_CHAR_LIST);
validator.SetIncludes(includeList);

ngpaton
Knows some wx things
Knows some wx things
Posts: 25
Joined: Tue May 20, 2008 8:23 am

Post by ngpaton » Wed Oct 14, 2009 8:58 am

Hi,

Can't you just use:

Code: Select all

wxTextValidator  validator(wxFILTER_ALPHANUMERIC);
Otherwise the validator will have to search through the list of includes for every character entry. I assume the above uses the isalnum() macro instead which will be much more efficient.

Cheers

Nigel

Post Reply