Forum Discussion
Mauricio_Cusine
Aug 22, 2007Nimbostratus
Validate IP address with regexp
Hello,
I am trying to check if a IP address is valid in the bigip with regexp (I don't know if anybody know other method).
The regexp is the follow but don't work. Anybody can help me?....
Feb 21, 2008
Regexps are not always the best solution. If all you are concerned about is whether the string is in the form of a.b.c.d where a,b,c,d are between 1 and 255 inclusive, how about this solution:
set addr "10.10.10.10"
set a [getfield $addr "." 1]
set b [getfield $addr "." 2]
set c [getfield $addr "." 3]
set d [getfield $addr "." 4]
if { (1 <= $a) && ($a <= 255) &&
(1 <= $b) && ($b <= 255) &&
(1 <= $c) && ($c <= 255) &&
(1 <= $d) && ($d <= 255) } {
log local0. "$addr is a valid IP Address"
} else {
log local0. "$addr is NOT a valid IP Address"
}
This will definitely be less CPU intensive than running the regular expression and should cover all the corner cases.
-Joe
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects