Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Telephone No Checking

 
Alex Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of a regexp like ".+\\-.+", try something like "\\d{2,3}-\\d{7}".
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Alex Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic