Skip to content

IPv4 validation regex validates faulty ip adresses #1409

@vdueck

Description

@vdueck

Hi,
the class IpV4FormatValidator contains a regex:
private const string IpV4RegexExpression = "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$";
This one supports also an ip address with only three parts, like: 192.168.178

A correct one would be: ^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$

I got this one from regular-expressions-cookbook@oreilly. Basically these are the same, but the implementation is missing the
"?:(?:" at the start and "\" in the middle.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions