View Full Version : Check for "@" in a field
ekrub
06-18-2003, 10:11 PM
How do I check a field to find the "@" symbol? I want to validate an email address. Better yet, can anyone show me how to validate the email address period?
jsawkang
06-19-2003, 12:18 AM
npos=Instr(f.txtemail.value,"@")
If npos = 0 Then
response.write "Invalid email Address!"
End If
ekrub
06-19-2003, 01:26 AM
thanks a million
that's acutally a poor way of validation for email addresses.
use Regular Expressions.
Here is one that I wrote and use:
myemail="EnetrEmail@here.com"
set objRegExp= New RegExp
objRegExp.Global = false
objRegExp.IgnoreCase=false
objRegExp.pattern= "([\w]+@[a-zA-Z0-9-]+\.[a-z]{2,3}$)"
if objRegExp.test (myemail)=true then
response.write "This is a valid Email address"
else
response.write "This is not a valid email address"
end if
set objRegExp=nothing
this will check for the @ symbol plus it will check for 2 to 3 letter extensions such as .com .cc etc. If there is only 1 letter or more than 3 letters at the end, then it will come back invalid.
It also checks for non alphanumeric chars in the domain name with the exception of ( - ) which is used in some domain names.
just adjust the varialbe MYEMAIL to what you use. Make sure you change it in this line too: if objRegExp.test (myemail)=true then
or it will not work.
if you need more help on using this, let me know.
ekrub
06-23-2003, 01:05 PM
I am in Trinidad (in the Caribbean), and some of the companies here use (.co.tt) down here. Is it that I just change this line of the regrex to 2,5?
e.g.
objRegExp.pattern= "([\w]+@[a-zA-Z0-9-]+\.[a-z]{2,5}$)"
Also, where can I get information on regular expressions in VBscript? The tutorial I did at w3schools.com didn't mention it. Actually, where can I get a tutorial that will take me to a VERY comfortable level in VBscript?
if you use this it should work
objRegExp.pattern= "([\w]+@[a-zA-Z0-9-]+\.[a-z\.]{2,5}$)"
For Reg Exp
http://www.4guysfromrolla.com/webtech/090199-1.2.shtml
vBulletin v3.0.3, Copyright ©2000-2012, Jelsoft Enterprises Ltd.