You can use regular expressions for this.
Googling for
javascript phone number validation gives some links that look interesting.
(Note: JavaScript doesn't have anything to do with
Java. We do have a forum about HTML and JavaScript here, so I've moved your question there for you).