Validate IP Address

liunx

Guest
If I want to make sure that someone has sumbitted a valid (in format>Bobba Buoy
07-09-2007, 05:38 PM

Oh I'm sorry. I need an asp version.....Actually, 銉ュ搶?s version will also match the numbers upto 999.999.999.999 and an I.P range will only go as high as 255.255.255.255 so you could use the following RegExp.


<%
dim rx,ip1,ip2

ip1="192.201.35.6"
ip2="999.999.999.999" 'out of range

set rx=new regexp
with rx
.pattern="\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b"
end with
Response.Write "IP1<br />"
if rx.test(ip1) then
Response.Write "Matched"
else
Response.Write "No Match"
end if
'----------test 2
Response.Write "<br /> IP2<br />"
if rx.test(ip2) then
Response.Write "Matched"
else
Response.Write "No Match"
end if
%>
 
Back
Top