How To check if string is the IP adress?
I have problem how to check that entered string is the IP adress, anyone have solutions?
|
Re: How To check if string is the IP adress?
You want to test if it's exactly and only a valid IP (0 .. 255 ) ? Or just if IP is containing the string.
|
Re: How To check if string is the IP adress?
Explode the string using '.' as the delimiter. Then, verify you have 4 numerical elements and each one is >= 0 and <= 255.
|
Re: How To check if string is the IP adress?
Here a safe example using regex to check if the string is exactly a valid IP :
Code:
You have just to call IsValidIP() in your function : Code:
As notes, I'm using regex_compile() because it's something you will probably check severals times so It's better to pre-compile the pattern one time. Also since the pattern use ^ which is the default control char in Pawn, it's necessary to change it by another character. I've choose # but you can change it. |
Re: How To check if string is the IP adress?
There is another way?, Sorry the off topic
PHP Code:
|
Re: How To check if string is the IP adress?
what ?
|
Re: How To check if string is the IP adress?
Quote:
EDIT: Sorry in english is octet |
Re: How To check if string is the IP adress?
I wrote this because it was easy:
Code:
|
Re: How To check if string is the IP adress?
Bad way of checking. Just because there are few '.' doesn't mean that it's an IP. :p
|
Re: How To check if string is the IP adress?
I thought an IP must have 4 numbers?
|
| All times are GMT -4. The time now is 17:04. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.