Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How do I validate Phone numbers in java/ email addresses

  Asked By: Lucas    Date: May 19    Category: Java    Views: 2227
  

How do I validate email addreses without using java.
If you get passed a String


As well how do I validate phone numbers getting passed
by string.

WITHOUT USING REGULAR EXPRESSIONS?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Ann Evans     Answered On: May 19

Well, let's see, you can't use Java and you can't use regular  expressions.
Maybe you should use another language then? :)

 
Answer #2    Answered By: Dan Romero     Answered On: May 19

I meant to say in java  code,
not by using regular  expressions


 
Answer #3    Answered By: Clint Garcia     Answered On: May 19

If you don't want to use regular  expressions in any way shape or form I
suggest you check out StringTokenizer and just token jump though the
string, with your delimeters set to @ and .

Regular expressions  would be neeter though.

 
Answer #4    Answered By: Wilfred Young     Answered On: May 19

validation of phone  numbers strongly depends on the country you're
working in; in USA you have very easy phone numbers, they all follow
the format aaa.ppp.nnnn where aaa = area code, ppp = prefix, and nnnn
= number within this prefix. However, in different countries you have
utterly different systems; the USA is the only country that I know
where the area code always has the same length; in Germany you have
area codes between 3 and 6 digits, in Italy you sometimes have to
dial a 0 as the first digit of area code and sometimes not, and the
like... In order to parse phone numbers  for validity you first should
know very well for what countries you're doing this.

Second problem is the use of delimiting characters. I've seen US
phone numbers in different formats, such as 262-555-1234 or
262.555.1234 or even 262/555 1234 and some more. So maybe you should
first try to find out whether you can rely on a particular format to
parse.

On to the actual process of parsing.
Every Java string  has a fixed length (as long as you look at the
string and don't change it, of course). So you could set up a loop
over all the characters in one string:
for (int currentIndex = 0; currentIndex <
myString .length(); currentIndex++)
if (...)
{ ... }

I assume you want to know what condition to write into the if()
clause? Well, as I wrote above I suggest you first find out what
format of numbers you may scan; then we can see how to do it.

About email  addresses: that's easier. There are official documents as
to what characters may comprise a valid email address; these
documents can be obtained for example from http://www.rfc.org , but
in general you can assume that an email address always looks like
this:
some.one@...
The part "some.one" must start with a letter, then there may be an
arbitrary number of letters, digits, underscores, dots '.', and
dashes.
The part "some.where.tld" (tld = Top Level Domain, these are managed
worldwide by the NIC, try http://www.nic.org (?)) is built in the
same way.
This means that in your loop above you have to check that:
- each part begins with a letter,
- that there is exactly one at character '@' and that this is neither
at the beginning nor at the end of the string,
- that after the initial letter in both parts only allowed characters
follow.
If you feel confident enough with Java, you can try to check that the
TLD part only has one of the allowed values, but that's a bit
dangerous because they may be expanded at any time.

 
Answer #5    Answered By: William Bouchard     Answered On: May 19

Define validate.

If you just want to check 555-555-5555 then split the string  on - and
check the size of each element.

 
Answer #6    Answered By: Jean Bell     Answered On: May 19

form command line or xterm

telnet <anysmtpserv> 25
rcpt to: blabla@<mailserver>

then u will receive okey or not okey.

but this is for domain name only

so in the end. u can't do this without sending an test email.

 
Didn't find what you were looking for? Find more on How do I validate Phone numbers in java/ email addresses Or get search suggestion and latest updates.




Tagged: