This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I'm trying to validate email and phone number on the server. It works but trying to validate if the email is entered correctly. Also phone number has the correct number of digits.
Here's what I have so far not sure how to write it
For some reason I can't place the code in here. It says I have a illegal HTML code < I don't have any HTML code. Can somebody give me some advice here? [ December 14, 2004: Message edited by: Jim Shapt ]
tough going. Email addresses can be pretty much anything, depending on where they're used. Generally, all you can say is that it's made up of 2 strings with an at-sign (@) in between but that's not always the case (for example on internal company networks).
Much more than that you can't say...
Phone numbers are even worse. Most will be at least 3 digits long (again on internal networks), and can be far longer (12 or more for international numbers).
One place to start is to decide what kind of phone numbers and email addresses you are going to accept. As mentioned above, there are different variations in some situations. Perhaps the first step in this decision process is identifying who will use this program. Will they be likely to enter just their email user name and expect it to be delivered on the local network? Typically this can be avoided by forcing them to enter a domain name. For phone numbers, are you going to allow international prefixes or just the standard format in your own country?
Consider these questions and try to come up with an informal description of what is (and is NOT) allowed as an email address and as a phone number. Feel free to post here as you are thinking about the issues involved. Hopefully the questions above sparked some thoughts. We'll be glad to help you out from there.
I'd recommend using the javax.mail.internet.InteretAddress class to validate SMTP email addresses since it will do it all for you (there nothing out the box if you want to validate another protocol).
To get you going (and to save you having to read RFC822) I'll can extend on what Jeroen has already told you: SMTP email addresses do not need to include an '@' sign. They can contain white space. And can be "unfolded" - which means they span more then one line. They can include commas and angle brackets (i.e. <> ) so long as they are in the correct place. [ December 15, 2004: Message edited by: Paul Sturrock ]