prohbit shift key in edit box............
-
i want to make user to only input numbers (1 to so on) but not spectial charters using shift like (%,#,@,!,^,&,*,()) etc
-
The below code will block the special charcters but permits alphabets and numbers
void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if( !isdigit(nChar) && !isalpha( nChar ))
{
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
} -
The below code will block the special charcters but permits alphabets and numbers
void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if( !isdigit(nChar) && !isalpha( nChar ))
{
return;
}
CEdit::OnChar(nChar, nRepCnt, nFlags);
}void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it
-
void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it
-
ani_ikram wrote:
well plz tell me how to do it
:doh: Just modify the checking as follows
if( !isdigit(nChar) && !isalpha( nChar ) && nChar != _T('.'))
-
i want to make user to only input numbers (1 to so on) but not spectial charters using shift like (%,#,@,!,^,&,*,()) etc
-
void EditEx::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if( !isdigit(nChar) && !isalpha( nChar )) { return; } CEdit::OnChar(nChar, nRepCnt, nFlags);} i hv used this method but its also restricting to enter float value while i want to enable float numbers as well plz tell me how to do it
BTW, if you only wanted to have an edit control into which you can enter a float value, there are hundreds of article about that subject, you only have to search for it on codeproject. Here[^] is an example. The problem with your approach is that it is not secure: nothing prevents the user to enter a dot several time. So, instead of reinventing the wheel and rewriting the validation code all over again(it's not that trivial because, you have also to take into account that the user might delete some characters, change the cursor location, ...) why don't you look for a control that does this already ?
Cédric Moonen Software developer
Charting control [v1.5] OpenGL game tutorial in C++ -
if you want to use only numbers than you can use number property of EditBox.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
if you want to block Special character than you can subclass your edit control and handle OnChar function like this.
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char szBuffer[100] = {0};
short int nCounter = 0;
short int iTemp = 0;
int iStartChar = 0;
int iEndChar = 0;if(nChar != VK\_BACK && nChar != VK\_TAB ) { if(nChar != '.' (nChar < '0' || nChar > '9') && (nChar < 'a' || nChar > 'z')&&(nChar < 'A' || nChar > 'Z'))//here write those character you want to enter { return; } GetWindowText((LPTSTR)szBuffer, sizeof(szBuffer)); } CEdit::OnChar(nChar, nRepCnt, nFlags);
}
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
-
if you want to block Special character than you can subclass your edit control and handle OnChar function like this.
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
char szBuffer[100] = {0};
short int nCounter = 0;
short int iTemp = 0;
int iStartChar = 0;
int iEndChar = 0;if(nChar != VK\_BACK && nChar != VK\_TAB ) { if(nChar != '.' (nChar < '0' || nChar > '9') && (nChar < 'a' || nChar > 'z')&&(nChar < 'A' || nChar > 'Z'))//here write those character you want to enter { return; } GetWindowText((LPTSTR)szBuffer, sizeof(szBuffer)); } CEdit::OnChar(nChar, nRepCnt, nFlags);
}
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
Do you have an aversion against
isalpha()
andisdigit()
?"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch