Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validation using Regular Expressions??

 
Karthikeyan Rajendraprasad
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to validate whether a given email id to be a valid one ? or how should we go about in validating a email id?
 
Wael Aoudi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Im not exactly positive this is what you're looking for but i hope this code helps.
<CFFORM ACTION="">
Email: <CFINPUT TYPE="Text" NAME="email"
VALIDATE="regular_expression"
PATTERN=" ^([_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.
(([a-z]{2,3})|(aero|coop|info|museum|name)))?$"
MESSAGE="Email is improperly formatted">
<INPUT TYPE="Submit">
</CFFORM>
Thank you,
Wael Aoudi
P.S. I got this from the following link which has a detailed explanation of CFForm. Therefore that code is not mine just to make it clear it is Charlie Areharrts.
http://www.sys-con.com/coldfusion/article.cfm?id=379&count=5104&tot=4&page=2
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthikeyan,
Assuming a valid eMail address contains alphanumeric characters, followed by the "@" character, followed by more alphanumeric characters -- separated with a period, for example:
MaoTseTung@china.com
Then the following is some java code to validate such an eMail address.
[Note, this is not a definitive answer -- it is only to help you understand how it works.]
My points of reference for arriving at the below code were:
'regex' page at Roedy Green's "Java Glossary"
javadoc of the "java.util.regex.Pattern" class

Good Luck,
Avi.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karthikeyan,
The answer to your question is yes: this is exactly the sort of thing that regex was designed for. As a matter of fact, it's the opening example in my book, right on page 1.
chances are, the pattern you're looking for lines along the following


However, if you need more robust checking( including IP email addresses, etc.), you'll find them in the book, along with explanations of how they're derived.
If you don't want to buy my book, try checking www.regexlib.com . They have great stuff, though you should validate it before using it, as they also have a lot of mistakes.
All best,
M
[ April 14, 2004: Message edited by: Max Habibi ]
 
Karthikeyan Rajendraprasad
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou friends,
i think i have to dive inside this topic and do some R&D. lets see how it turns out(i hope it will be able to replace a large prtion of code that i have been using for such validations and help the people who are going to do maintenance/enhancements in future)
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Of course any checking that's really thorough will also involve some way to determine whether the domain at least is an existent one.
But that's beyond text processing RegEx does and goes into networking (attempt to do a DNS lookup for example).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic