Posted By

Scooter on 07/26/08


Tagged

regular expressions


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

benrudolph
asifrizvigmailcom


isValidIP


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/07/isvalidip.html

  1. <%
  2. ' Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved.
  3. '
  4. ' This work is licensed under the Creative Commons Attribution License. To view
  5. ' a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or
  6. ' send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
  7. ' 94305, USA.
  8.  
  9. ' Validate an IP address.
  10. function isValidIP(ip)
  11. dim regEx
  12.  
  13. set regEx = new RegExp
  14.  
  15. with regEx
  16. .IgnoreCase = True
  17. .Global = True
  18. .Pattern = "^([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})(\.([1]?\d{1,2}|2[0-4]{1}\d{1}|25[0-5]{1})){3}$"
  19. end with
  20.  
  21. if regEx.Test(trim(CStr(ip))) then
  22. isValidIP = True
  23. else
  24. isValidIP = False
  25. end if
  26.  
  27. set regEx = nothing
  28. end function
  29. %>

Report this snippet  

You need to login to post a comment.