Skip to main content
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
  • 88.3k
28 votes
Accepted

Verifying IPv6 addresses

You can change valid_characters to a string. 'ABCDEFabcdef:0123456789'. You can use ...
Peilonrayz's user avatar
  • 44.6k
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,501
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 ...
Loki Astari's user avatar
  • 97.7k
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.9k
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
13 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
  • 44.6k
13 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
  • 13.1k
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.7k
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.5k
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
  • 14.2k
11 votes

C Program which compares software version strings

Don't strtok + atoi. Use strtol, which (a) doesn't need a mutable input, (b) has much better ...
vnp's user avatar
  • 58.7k
10 votes

Verifying IPv6 addresses

Various comments in no specific order. The 2 last statements are identical, thus it is not relevant to check invalid_segment. You could write: ...
SylvainD's user avatar
  • 29.8k
10 votes

Validator for mathematical expression in infix form

Don’t write using namespace std;. You can, however, in a CPP file (not H file), or inside a function, put individual ...
JDługosz's user avatar
  • 11.7k
10 votes
Accepted

Python 3.6+ function to ask for a multiple-choice answer

The while True is fine, and is probably the best way to do it. However, the rest of the flow control is a bit clumsy. By rearranging a few statements, you can ...
200_success's user avatar
9 votes

Program to check if a date is valid or not

For the most part, looks pretty good to me! Format You didn't use underscores to separate the words in a lot of variable names, which kinda bothered me. Snake_case is recommended by PEP8, so I ...
auden's user avatar
  • 441
9 votes
Accepted

Bash script to truncate subject line of incoming email

Be sure to read the relevant RFCs that govern e-mail headers! Specifically: RFC 2822, Section 1.2.2: Header names are case-insensitive. RFC 2822, Section 2.2.3: Header fields may be line-folded: 2....
200_success's user avatar
9 votes
Accepted

IP4 strings validator

<stdbool.h> Unless you need compatibility with C89 for some reason, I would use bool for the return type of the function ...
alx - recommends codidact's user avatar
9 votes
Accepted

C function to check the validity of a date in DD.MM.YYYY format

Use descriptive variable names Instead of int a, b, c, give them more descriptive names: int day, month year; ...
G. Sliepen's user avatar
  • 69.3k
9 votes

Input validation

Non-exported functions Declare get_valid_input and flush as static since you're in a single ...
Reinderien's user avatar
  • 71.1k
9 votes
Accepted

Generate filesystem usage report using Awk

ISO dates Yeah, I get it that you have a pre-defined data format. Input Data Format Month (in MM.YYYY format) But that's significantly less than ideal. If feasible, try to get new records produced ...
J_H's user avatar
  • 42.2k
8 votes

Verifying IPv6 addresses

According to the Wikipedia article on IPv6 addresses, there are alternative ways of representing IPv6 addresses that you are not taking into account with this approach: Leading zeroes in a group may ...
Daniel's user avatar
  • 4,632
8 votes

Versatile string validation

There's a bug: you're not checking if the last character is a letter or digit, only that it isn't a hyphen, so this fails to reject "abcdef&". Denis' solution ...
Pieter Witvoet's user avatar
8 votes

Chess move validator

Use Standards Use standard notations and representations whenever possible: see Algebraic Notation for example. Avoid Global Variables Board.CHESS_BOARD is a ...
abuzittin gillifirca's user avatar
8 votes

Validate IP4 address

A doc string reads nicer then # blockcomments Consider making a doc string of that function, so you can do help(validate_ip) and it will print the doc string in the ...
Ludisposed's user avatar
  • 11.8k
8 votes

Fluent Validation of Objects

Fluent API Fluent APIs are generally very useful but one has to be very careful with them as there is a chance of making them overfluent. This means that you try to create an API for every possible ...
t3chb0t's user avatar
  • 44.7k
8 votes

Input validation

General Observations The code is quite readable. Using void in the function declarations is good. Using stdlib.h for EXIT_FAILURE is good, but the ...
pacmaninbw's user avatar
  • 26.1k
8 votes

Compact VBA Validator for Excel Names

The name parameter should be passed ByVal, and I would have named the function IsValidName ...
Mathieu Guindon's user avatar
7 votes
Accepted

Validating user-provided control points for a Bézier curve

There are things that can be improved: You could return the points instead of asigning the global variabel p You could split the function in two functions: ...
Jan Kuiken's user avatar
  • 1,523

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