This week's book giveaway is in the
Agile and other Processes
forum.
We're giving away four copies of
The Mikado Method
and have Ola Ellnestam and Daniel Brolund on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
The Mikado Method
this week in the
Agile and other Processes
forum!
JavaRanch
»
Java Forums
»
Java
»
JSF
Author
email validation problem
srinivas srini
Greenhorn
Joined: Feb 03, 2004
Posts: 23
posted
Jul 13, 2011 00:02:26
0
Hi
I have a validation for email which should allow only
,
or
;
the validation works fine if I enter the following in the text field
mail1@email.com,,,,,,,mail2@email.com
but the validation does NOT work if I enter the following in the text fields
mail1@email.com;;;;;;;mail2@email.com
the following will work properly
mail1@email.com;mail2@email.com
this is the regular expression that I have written in my validator class
my_pattern = Pattern.compile("^((\\s*[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+\\.[a-zA-Z0-9]{2,4}\\s*[,;:]){1,100}?)?(\\s*[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+\\.[a-zA-Z0-9]{2,4})?\\s*$"); Matcher matcher = my_pattern.matcher(mailid); if(matcher.matches()) { do something....here... }
can anyone let me know what's going wrong here? any solution to this would be very much helpful.
Thanks in advance.
Ogeh Ikem
Ranch Hand
Joined: May 13, 2002
Posts: 180
posted
Jul 13, 2011 06:10:46
0
You might find this useful
class EmailTest { void emailValidator() { final String sp = "\\!\\#\\$\\%\\&\\'\\*\\+\\-\\/\\=\\?\\^\\_\\`\\{\\|\\}\\~"; final String atext = "[a-zA-Z0-9" + sp + "]"; final String atom = atext + "+"; //one or more atext chars final String dotAtom = "\\." + atom; final String localPart = atom + "(" + dotAtom + ")*"; //one final String letter = "[a-zA-Z]"; final String letDig = "[a-zA-Z0-9]"; final String letDigHyp = "[a-zA-Z0-9-]"; final String rfcLabel = letDig + "(" + letDigHyp + "{0,61}" + letDig + ")?"; final String domain = rfcLabel + "(\\." + rfcLabel + ")*\\." + letter + "{2,6}"; final String addrSpec = "^" + localPart + "@" + domain + "$"; String email = "mail1@email.com;;;;;;;mail2@email.com"; System.out.print(email.trim().matches(addrSpec)); } public static void main(String[] args){ new EmailTest().emailValidator(); } }
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: email validation problem
Similar Threads
Validate multiple Email address in validation.xml file
Quick Javascript & RegEx quuestion
java string[] splitting for email id
regexp on email address
Replace text by HTML links
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter