Posted By

Scooter on 08/02/08


Tagged

regular expressions


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

nelda751
benrudolph
nickian


isValidEmail


 / Published in: ASP
 

URL: http://reusablecode.blogspot.com/2008/08/isvalidemail.html

Refer to the linked blog post for a broken-down explanation of the different components of the pattern.

  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 e-mail address.
  10. ' Supports quoted local part as well as IP address for the domain part.
  11. function isValidEmail(email)
  12. dim regEx
  13. dim result
  14.  
  15. set regEx = new RegExp
  16.  
  17. with regEx
  18. .IgnoreCase = True
  19. .Global = True
  20. .Pattern = "^[^@]{1,64}@[^@]{1,255}$"
  21. end with
  22.  
  23. result = false
  24.  
  25. ' Test length.
  26. if regEx.Test(email) then
  27. regEx.Pattern = "^((([\w\+\-]+)(\.[\w\+\-]+)*)|(\"[^(\\|\")]{0,62}\"))@(([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9]{2,})|\[?([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}\]?)$"
  28.  
  29. ' Test syntax.
  30. if regEx.Test(email) then
  31. result = true
  32. end if
  33. end if
  34.  
  35. isValidEmail = result
  36. set regEx = nothing
  37. end function
  38. %>

Report this snippet  

You need to login to post a comment.