Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-23-2007, 07:37 PM
Member
 
Join Date: Jul 2007
Posts: 32
valery is on a distinguished road
how to validate an email with pattern object
I'm trying to validate an email with pattern object.
and it validates only 'xxxxx@'
I want that validates all 'xxx@zzz.yy'
the code is the following one:
Code:
public static boolean validateEmail(String ca) { Pattern pattern= Pattern.compile("[a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+"); Matcher en= pattern.matcher(ca); return !en.matches(); }
what's the problem?
what am I doing wrong?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-26-2007, 01:07 AM
Member
 
Join Date: Jul 2007
Posts: 55
Seemster is on a distinguished road
search on google. there's tons of code that does this.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 07-26-2007, 11:44 AM
Member
 
Join Date: Jul 2007
Location: England, Bath
Posts: 47
shanePreater is on a distinguished road
Quote:
Originally Posted by valery View Post
I'm trying to validate an email with pattern object.
and it validates only 'xxxxx@'
I want that validates all 'xxx@zzz.yy'
the code is the following one:
Code:
public static boolean validateEmail(String ca) { Pattern pattern= Pattern.compile("[a-zA-Z0-9_]+[.[a-zA-Z0-9]+]*@[a-zA-Z0-9_]+[.[a-zA-Z]+]+"); Matcher en= pattern.matcher(ca); return !en.matches(); }
what's the problem?
what am I doing wrong?
From a quick glance I would say you have forgotton to escape the '.' character. In regex the . defines any character so to explicitly search for just a . you need \. instead.
Also remember as this is in a string the \ character is a java string escape character so you actually need to escape that as well.

So basically replace . with \\. and that will get you going again.

Whenever I am doing regex I always keep a cheat sheet to hand which I found on Web design, development and marketing - ILoveJackDaniels.com

Hope this helps.
__________________
Shane Preater -
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to validate date using SampleDateFormat Java Tip java.text 0 04-04-2008 04:38 PM
repaint validate doLayout Gajesh Tripathi AWT / Swing 1 10-27-2007 08:53 PM
How to validate date using SampleDateFormat JavaBean Java Tips 0 10-04-2007 11:31 PM
how to validate a xml file with schemas via SAX oregon XML 3 08-01-2007 07:15 PM
validate hex character paul New To Java 1 07-25-2007 11:08 PM


All times are GMT +3. The time now is 10:00 AM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org