GeeCON Prague 2014*
The moose likes Java in General and the fly likes Telephone No Checking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Telephone No Checking" Watch "Telephone No Checking" New topic
Author

Telephone No Checking

Alex Mann
Greenhorn

Joined: Dec 15, 2006
Posts: 4
Sir,
My tel. no. example should be 016-1234567 or 04-1234567 (as long it got a "-" inside). I already made sure that between the number has "-" but still cannot restrict alphabets to enter in other than number. For now my form still can accept alphabets like "abc-defghtb".

Sir, can help me? or can give me some idea
THANK You very much.
-----------------------------
Here is my code:--

public boolean chkInputAdd(){
if (telNo == null) {
setMessage("Please enter the telephone number \n");
return false;
}

if (validateTelNo()) {
setMessage("The telephone num , should in xxx-xxxxxxx format \n");
return false;
}
return true;
}

public boolean validateTelNo() {
Boolean isValid = false;
if (!telNo.matches(".+\\-.+")) {
return true;
}
return isValid;
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

This forum is for questions on JSP. Regular expression questions should be addressed in the Java in General forum to which I have moved this post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42043
    
  64
Instead of a regexp like ".+\\-.+", try something like "\\d{2,3}-\\d{7}".


Ping & DNS - my free Android networking tools app
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Your number check to those restrictions will work fine for numbers inside most countries, but will fail miserably when international numbers are used.
A fully qualified number would be something along the lines of (+12)(0)(12)-1234567 with the dash being optional, and some people replacing the + with 00 or 00-.
You will also optionally see a space between the 3 and 4 in the last sequence, leading the most elaborate number you have to check to be "(00-12)(0)(12)-123 4567".


42
Alex Mann
Greenhorn

Joined: Dec 15, 2006
Posts: 4
Sir,
I copy the code and it work sucessfully. For the international number, I will keep it in mind and try it on next time.


You helped me a lot
Thank you, Sir
Alex
 
GeeCON Prague 2014
 
subject: Telephone No Checking