Skip to content

Conversation

@Pratyush2240
Copy link
Contributor

This PR updates the IPv4 validation regex to strictly enforce the standard IP address format, addressing the failing test cases from #2176.

Changes
Strict Format Validation: Updated regex to properly validate IPv4 addresses (0-255 per octet)
Reject Invalid Formats: Now correctly handles edge cases:
Rejects non-numeric IPs (e.g., "a.b.c.d")
Rejects incorrect segment counts (e.g., "1.2.3.4.5")
Rejects out-of-range values (e.g., "256.256.256.256")
Rejects leading zeros (e.g., "01.02.03.04")
Maintains Compatibility: Still accepts all valid IPv4 addresses
Testing

The following test cases now pass:
isValidIP("1.2.3.4") // true
isValidIP("255.255.255.255") // true
isValidIP("a.b.c.d") // false
isValidIP("1.2.3.4.5") // false
isValidIP("256.1.2.3") // false
isValidIP("01.02.03.04") // false
Related Issues
Fixes #2176

Additional Context
This change ensures that the IP validation is both strict and accurate, preventing false positives for invalid IP formats while maintaining compatibility with all valid IPv4 addresses. The updated regex follows the standard IPv4 specification more precisely.

Feedback submitted

…nforce IPv4 octet ranges

Tighten IPv4 pattern to enforce 0-255 per octet, rejecting invalid addresses like 256.256.256.256 and 999.999.999.999

Replace loose IPv6 matcher with comprehensive pattern covering full, compressed, link-local with zone IDs, and IPv4-embedded forms
@ravichandra1998g ravichandra1998g self-assigned this Oct 22, 2025
Copy link
Contributor

@ravichandra1998g ravichandra1998g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me.

approving this as this new code is an enhancement over the old one, covering all the edge cases.

@ravichandra1998g ravichandra1998g merged commit 9a316d7 into ServiceNowDevProgram:main Oct 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue with IP Validation regex

2 participants