forked from GeethaCharan-323/MADlab
-
Notifications
You must be signed in to change notification settings - Fork 1
/
InputChecking.java
81 lines (71 loc) · 1.72 KB
/
InputChecking.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class InputChecking extends MIDlet implements CommandListener{
public Display display;
public Form form;
public TextField tf;
public Command check,exit;
public InputChecking(){
display=Display.getDisplay(this);
form = new Form("CHECK PHONE NUMBER");
tf = new TextField("Enter Number:","",30,TextField.ANY);
form.append(tf);
check = new Command("CHECK",Command.OK,1);
exit= new Command("EXIT",Command.EXIT,1);
form.addCommand(check);
form.addCommand(exit);
form.setCommandListener(this);
}
public void startApp(){
display.setCurrent(form);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
notifyDestroyed();
}
public void commandAction(Command c,Displayable d){
if(c==exit){
destroyApp(false);
}
else if (c==check){
performMatching();
}
}
public void performMatching(){
String s = tf.getString();
String areaCode="";
int k=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)==' '){
k=i;
break;
}
else{
areaCode+=s.charAt(i);
}
}
boolean areaFlag=false;
boolean countFlag=false;
if(areaCode.equals("111")||areaCode.equals("041")||areaCode.equals("050")||areaCode.equals("0400")||areaCode.equals("044")){
areaFlag=true;
}
int count=0;
for(int i=k+1;i<s.length();i++){
count+=1;
}
if(count>=6 && count<=8){
countFlag=true;
}
//alerts
String alertMessage;
if(countFlag&&areaFlag){
alertMessage="Valid Number";
}
else{
alertMessage="Invalid Number";
}
Alert alert = new Alert("ALERT",alertMessage,null,null);
display.setCurrent(alert);
}
}