Original Post
🔒 Locked
Field Validation
Advertisement
struct notNumber{ //Functor to check if a character isn't a digit. struct notDigit { operator()(char const &c) { return c < '0' || c > '9'; } }; //Return true if field is not a number. bool operator()(string const &field) { return find_if(field.begin(), field.end(), notDigit()) != field.end(); }};The above notNumber functor will check if a std::string meets contains any character other than [0-9].
Quote:
Original post by gisdev
If you're using std::string:
*** Source Snippet Removed ***
[edit]Simplified check[/edit]
I like that better.
it doesn't work with -5 or 3.142 or 1e-7
If you want to deal with those properly you'll need to look into locales. For example some countries would have 3,142 instead of 3.142.
Personally I would use boost.lexical_cast and let it worry about whether the conversion is correct.
If you want to deal with those properly you'll need to look into locales. For example some countries would have 3,142 instead of 3.142.
Personally I would use boost.lexical_cast and let it worry about whether the conversion is correct.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement