Check if a string is a valid IPv4 address.
Code
Generalrequire 'ipaddr'
begin
return IPAddr.new(ip).ipv4?
rescue IPAddr::InvalidAddressError
return false
endParameters
The IP address to validate
Server
More Ruby Snippets
Check Password Strength
Check if a password meets strength requirements (8+ chars, uppercase, lowercase, number, special).
Is Alpha Only
Check if a string contains only alphabetic characters.
Is Alphanumeric
Check if a string contains only letters and numbers.
Is Empty
Check if a value is empty (null, empty string, array, or hash).
Is Numeric
Check if a string represents a valid number.
Validate Email
Check if a string is a valid email address.