Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern matching problem 1

Status
Not open for further replies.

nzgirl

Programmer
Feb 26, 2003
72
NZ
Hi All...
I'm wanting to check for invalid email addresses.
the rules I have so far =
SELECT Count(*) FROM FileName where
Email Not Like '%@%.%'
or Email Like '%@%@%'
or Email Like '%.'
or Email is Null
or Email like '% %' (theres a space in there)
and this catches most of them. I'm just wondering if theres a better way to do it...
so that rather than trying to catch all the wrong ones I'm only looking for the right ones...

The following is a regular expression (in PHP I think) for valid email addressses... can I do similar with SQL?
ereg("(.*)@(.*)(\.)(.*)",$string)

I've read a little on PATINDEX but it seems to need % as well so its similar to my current statements..

Any ideas?
Thanks
:)
 
I think the query you wrote cant really filter all the invalid email address.
If somebody type g~~123@yahoo.com or $$$@hotmail.com
These email address are invalid.But according to the query you wrote.It is a valid email address.

Valid email adress should be composited by a-z , A-Z , 0-9 ,'-' or '_' before @.
After @,there should be a-z,A-Z or 0-9 in between . and not ended by any other symbol other than english letter

Maybe you can use "ascii" to check each char in the email address.But it's going to take a lots of time if you check one by one.
 
Thanks for reminding me about the non alpha chars... they shouldn't be too much of a prob -I should be able to screen them using patindex....
any further ideas re regular expressions?

Thanks :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top