IS_IPV4() function in MySQL
Last Updated :
10 Dec, 2020
IS_IPV4() :
This function in MySQL is used to check whether a specified string is a valid IPv4 address. If it is a valid IPv4 address then it will return 1. Otherwise, it will return 0.
Syntax :
IS_IPV4(expr)
Parameter :
This method accepts only one parameter.
- expr – Input string which we want to check.
Returns : It returns 1 if the string is a valid IPv4 address. If the string is not a valid IPv4 address then it will return 0.
Example-1 :
Checking whether the given address is valid or not using IS_IPV4 Function.
SELECT IS_IPV4('10.4.2.256')
AS ValidOrNot;
Output :
So, we can see the given address is not a valid IPv4 address.
Example-2 :
Checking whether the given address is valid or not using IS_IPV4 Function.
SELECT IS_IPV4('12.8.5.255')
AS ValidOrNot;
Output :
So, we can see the given address is a valid IPv4 address.
Example -3 :
Checking whether a IPv6 address is valid IPv4 address or not using IS_IPV4 Function.
SELECT IS_IPV4('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
IPv4ValidOrNot,
IS_IPV6('2001:0db8:85a3:0000:0000:8a2e:0370:7334')
AS IPv6ValidOrNot;
Output :
IPV4VALIDORNOT |
IPV6VALIDORNOT |
0 |
1 |
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...