Say, I want to prevent user from inputting Russian character in
username, how to deal with it?
The codes I'm using now is:
------------------------------------------
for ( std::wstring::const_iterator it = userName.begin(); it !=
userName.end(); ++it)
{
// verify that each subsequent character is an alphanum
if (!std::isalnum(*it, std::locale::classic()) &&
// or is included in our valid chars set
(validCharsSet.find(*it) == validCharsSet.end()))
{
return false;
}
}
------------------------------------------
But it doesn't work. 8 1453
You have to use imbue method on locales and bind facets to enable it
Check the classic textbook on C++ IOStreams and Locaes by Angelika
Langer and Kalus Kreft
Alien posted: Say, I want to prevent user from inputting Russian character in username, how to deal with it?
int CharIsValid( char const c )
{
const char *p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
do if( c == *p ) return 0; while ( *++p );
return 1;
}
int StringIsValid( const char *p )
{
while (*p) if ( !CharIsValid(*p++) ) return 0;
return 1;
}
--
Frederick Gotham
Frederick Gotham posted: int CharIsValid( char const c )
int StringIsValid( const char *p )
I'd actually use a return type of "bool" in C++:
bool CharIsValid( char );
bool StringIsValid( const char * )
--
Frederick Gotham
Frederick Gotham posted: bool CharIsValid( char );
I should really test my algorithms before posting! The one I posted was
garbage... I'll give it another go:
bool CharIsValid( char const c )
{
const char *p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
do if( c == *p ) return true; while ( *++p );
return false;
}
--
Frederick Gotham
Frederick Gotham <fg*******@SPAM.com> wrote: Frederick Gotham posted:
bool CharIsValid( char );
I should really test my algorithms before posting! The one I posted was garbage... I'll give it another go:
If you take this path, you might as well use code that has been
already written:
bool CharIsValid( char const c ) {
return strchr ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz",
c) != 0;
const char *p = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz";
do if( c == *p ) return true; while ( *++p );
return false; }
regards
--
jb
(reply address in rot13, unscramble first)
Alien <Ma*****@gmail.com> wrote: Say, I want to prevent user from inputting Russian character in username, how to deal with it? The codes I'm using now is: ------------------------------------------ for ( std::wstring::const_iterator it = userName.begin(); it != userName.end(); ++it) { // verify that each subsequent character is an alphanum if (!std::isalnum(*it, std::locale::classic()) && // or is included in our valid chars set (validCharsSet.find(*it) == validCharsSet.end())) { return false; } } ------------------------------------------ But it doesn't work.
I agree with Fredericks approach: create a string of *all* valid
chars and check if each entered character can be found in there. You
have done that already for a subset of the valid characters.
regards
--
jb
(reply address in rot13, unscramble first)
Jakob Bieling wrote:
Alien <Ma*****@gmail.comwrote:
Say, I want to prevent user from inputting Russian character in
username, how to deal with it?
The codes I'm using now is:
------------------------------------------
for ( std::wstring::const_iterator it = userName.begin(); it !=
userName.end(); ++it)
{
// verify that each subsequent character is an alphanum
if (!std::isalnum(*it, std::locale::classic()) &&
// or is included in our valid chars set
(validCharsSet.find(*it) == validCharsSet.end()))
{
return false;
}
}
------------------------------------------
But it doesn't work.
I agree with Fredericks approach: create a string of *all* valid
chars and check if each entered character can be found in there. You
have done that already for a subset of the valid characters.
regards
--
jb
(reply address in rot13, unscramble first)
Can I set the local parameter to something like std::locale loc("C"),
so that still use the std::isalnum(...)?
template<Class CharType>
bool isalnum(
CharType _Ch,
const locale& _Loc
) const;
Just set the _Loc to pure English ASCII.
I've tried std::locale::classic() but failed.
Alien wrote:
Jakob Bieling wrote:
Alien <Ma*****@gmail.comwrote:
Say, I want to prevent user from inputting Russian character in
username, how to deal with it?
The codes I'm using now is:
------------------------------------------
for ( std::wstring::const_iterator it = userName.begin(); it !=
userName.end(); ++it)
{
// verify that each subsequent character is an alphanum
if (!std::isalnum(*it, std::locale::classic()) &&
// or is included in our valid chars set
(validCharsSet.find(*it) == validCharsSet.end()))
{
return false;
}
}
------------------------------------------
But it doesn't work.
I agree with Fredericks approach: create a string of *all* valid
chars and check if each entered character can be found in there. You
have done that already for a subset of the valid characters.
regards
--
jb
(reply address in rot13, unscramble first)
Can I set the local parameter to something like std::locale loc("C"),
so that still use the std::isalnum(...)?
template<Class CharType>
bool isalnum(
CharType _Ch,
const locale& _Loc
) const;
Just set the _Loc to pure English ASCII.
I've tried std::locale::classic() but failed.
Note: The character is w_char This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Andrew James |
last post by:
Gentlemen,
I'm currently in the process of designing a language which will be used
to specify sets of files on a WebDAV server, encoded in a URL. The aims
of the language are to (in no particular...
|
by: lawrence |
last post by:
I'd love to ask why this page is not rendering correctly in Safari on
a Macintosh but I suspect someone will tell me to validate the page
first. Nevertheless, if anyone sees an obvious reason that...
|
by: Robin Munn |
last post by:
I'm developing a simple proof-of-concept Web application, more as a
personal programming exercise than anything else, that presents the user
with a login form where they can type in a database...
|
by: =?Utf-8?B?YmJkb2J1ZGR5?= |
last post by:
Hi,
I am retrieving data from a binary field from a sql table and I am having a
problem with extra characters being tacked onto the end. The thePass
variable has some unknown spaces after it...
|
by: sophie_newbie |
last post by:
Hi, I want to store python text strings that characters like "é" "Č"
in a mysql varchar text field. Now my problem is that mysql does not
seem to accept these characters. I'm wondering if there...
|
by: Cylix |
last post by:
Is there any existing method in VB.NET or any 3-third party function
can find out the language in a string?
Let say, isChinese? isFrench?
|
by: DotNetNewbie |
last post by:
Hi,
I want to parse a string, ONLY allowing alphanumeric characters and
also the underscore '_' and dash '-' characters.
Anything else in the string should be removed.
I think my regex is...
|
by: parun |
last post by:
Hello, is there a possibility to log on to a user whose length is greater
than 8 characters. My system is AIX and system base authentication . At
IBM I found this information:
Limit Windows...
|
by: Peter |
last post by:
Hello
I have an UTF string, how can i detect what language it is?
thanks
from Peter (cmk128@hotmail.com)
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |