52 votes
Accepted

Password checker in Python

Concept Obligatory XKCD comic, before I begin: Enforcing password strength by requiring human-unfriendly characters is no longer considered good practice. Nevertheless, I'll review the code as you ...
200_success's user avatar
39 votes

Verifying a person's age

The biggest problem I see here is that you are printing a warning message to System.out and then using a default value for something which sounds like an Exception. ...
Simon Forsberg's user avatar
33 votes
Accepted

Accurate email syntax validation (no seriously)

"@"@example.com and "\ "@example.com both fail, but they are valid. ...
rhino's user avatar
  • 470
33 votes

Verifying IPv6 addresses

Python has a philosophy of "Batteries Included". Don't reinvent what's in the standard library! In particular, this code is much more easily written if we take advantage of ...
Toby Speight's user avatar
28 votes
Accepted

Verifying IPv6 addresses

You can change valid_characters to a string. 'ABCDEFabcdef:0123456789'. You can use ...
Peilonrayz's user avatar
  • 42.7k
24 votes

Accurate email syntax validation (no seriously)

Said this in chat already, but @ succeeds even although it is not a valid email address. You should require at least 1 character in the local part and 1 character ...
Pimgd's user avatar
  • 22.3k
24 votes

Accurate email syntax validation (no seriously)

I personally find it hard to fault your code. Actually I'm quite surprised about the absence of code. Other than a few PEP8 errors there are three changes that I would recommend. You remove both <...
Peilonrayz's user avatar
  • 42.7k
24 votes
Accepted

Program to check if a date is valid or not

Good work! While there is certainly room for improvement, it is good that you stuck it out and discovered a solution on your own. ...
Gerrit0's user avatar
  • 3,456
22 votes
Accepted

Validating Yes/No answers in C++

You have a common bug that will send you into an infinite loop. :-) When reading data (especially user input data) you must validate the read worked correctly. If the read fails and sets one of the ...
Martin York's user avatar
  • 94.3k
20 votes

Validating Yes/No answers in C++

For a beginner, that's very good code. There is one thing that almost all C++ programmers get wrong, and that's calling ::tolower with a ...
Roland Illig's user avatar
  • 21.2k
19 votes

Checking if each char in a string is a decimal digit

In the cctype header, you have the std::isdigit(int) function. You can use this instead of your conditions that check if the ...
user2296177's user avatar
  • 3,533
17 votes

"Suspicious comparison of integer references" while checking for a monotonically increasing sequence

You should only use == if you work with elementary data types (boolean, byte, char, short, int, long, float, long). If you use <...
MrSmith42's user avatar
  • 2,060
17 votes

Accurate email syntax validation (no seriously)

You seems to build your module to contain only validate as "public" function. You may want to enforce that by declaring ...
301_Moved_Permanently's user avatar
17 votes
Accepted

Simple object validator

Instead of using regular expressions to manipulate the expression string I prefer to do expression manipulation. While this can be a little daunting at first it turns out to be fairly simple. It ...
Corey's user avatar
  • 805
16 votes
Accepted

Is date 18+ years old?

What about this: function isDate18orMoreYearsOld(day, month, year) { return new Date(year+18, month-1, day) <= new Date(); } The ...
lex82's user avatar
  • 1,157
16 votes

Checking if each char in a string is a decimal digit

The other reviews have hit most of the important points, so I'll just provide a single line alternative that uses the C++11 std::regex_match. That function looks ...
Edward's user avatar
  • 65.3k
13 votes
Accepted

Input validation for a user

You could merge your two foreach loops using SelectMany in LINQ. So instead of : ...
IEatBagels's user avatar
  • 12.4k
12 votes
Accepted

Checking balanced parenthesis string

if(st.isEmpty()) return true; else return false; This can be simplified to return st.isEmpty();... Wait, that's not the ...
h.j.k.'s user avatar
  • 19.2k
12 votes

Accurate email syntax validation (no seriously)

The code that you've written is generally really good, but as you seem to have found parsing non-trivial strings starts to get kind of complicated, and has all sorts of room for nasty edge cases. Your ...
ymbirtt's user avatar
  • 840
12 votes
Accepted

Windows filepath and filename validation

For the if(filePath.Length >= 240) part, you can use the Path object. It throws a ...
Guillaume Beauvois's user avatar
12 votes

Binary file validity in C++/C++11: checking a binary header

The most unforgivable fault with this function is that calling isValidBuffer() also erases the buffer! That completely violates the Principle of Least Surprise. If ...
200_success's user avatar
12 votes
Accepted

Password Validation in Python

You shouldn't use bare excepts, this is as it can prevent things like KeyboardInterrupt. That's just bad. ...
Peilonrayz's user avatar
  • 42.7k
12 votes
Accepted

Checking some rules before a Telegram bot replies to a message

If you want to get rid of your nested code then you should make a function and use guard statements. If we simplify your code a bit, we can have: ...
Peilonrayz's user avatar
  • 42.7k
12 votes
Accepted

Pythonic way for validating and categorizing user input

Don't print promiscuously. You've broken your problem down into several small functions, which is a good general instinct. But you've undermined those functions by polluting them with side effects -- ...
FMc's user avatar
  • 12.6k
11 votes

Input validation for a user

You can do this with more easily by manually creating a ValidationContext and then calling a Validator.TryValidateObject ...
RobH's user avatar
  • 16.9k
11 votes
Accepted

"Suspicious comparison of integer references" while checking for a monotonically increasing sequence

Integer[] vs int[] This may be down to a 'personal preference' thing, but using primitive wrappers in an array instead of a <...
h.j.k.'s user avatar
  • 19.2k
11 votes

Validating integer or string input

You are clearly violating the Single Responsibility Principle (SRP) because the method is doing two things. You should use two methods where each validates one type only. You will see also that for ...
Heslacher's user avatar
  • 50.3k
11 votes
Accepted

Enforcing string validity with the C# type system

Review I find this is a very nice idea that I have borrow from you and while doing this I'd change a couple things to make it more mature and even more flexible. ...
t3chb0t's user avatar
  • 44.2k
11 votes

Validate IP4 address

def validateIP(ip): I would expect a name starting is (a useful hint that it returns a Boolean rather than some more complex ...
Peter Taylor's user avatar
  • 24.1k
11 votes

Repetitive validation of Console inputs

As you suggested, you have a lot of redundant code. And rightfully so you want to adhere to the DRY principle. All these input methods have the same pattern internally.. ...
dfhwze's user avatar
  • 13.9k

Only top scored, non community-wiki answers of a minimum length are eligible