File tree 10 files changed +144
-0
lines changed 10 files changed +144
-0
lines changed Original file line number Diff line number Diff line change
1
+ public class Validate01
2
+ {
3
+ public static void main (String [] args )
4
+ {
5
+ String firstName = "XXX" ;
6
+ String lastName = "YYY" ;
7
+ String address = "ZZZ IIII AAAA 5689" ;
8
+ String city = "Oxford" ;
9
+ String state = "Oxfordshire" ;
10
+ String zip = "OX37AF" ;
11
+ String phone = "+4477777" ;
12
+
13
+ if (!ValidateInput01 .validateFirstName (firstName ))
14
+ assert false ;
15
+ else if (!ValidateInput01 .validateLastName (lastName ))
16
+ assert false ;
17
+ else if (!ValidateInput01 .validateAddress (address ))
18
+ System .out .println ("Invalid address" );
19
+ else if (!ValidateInput01 .validateCity (city ))
20
+ assert false ;
21
+ else if (!ValidateInput01 .validateState (state ))
22
+ assert false ;
23
+ else if (!ValidateInput01 .validateZip (zip ))
24
+ System .out .println ("Invalid zip code" );
25
+ else if (!ValidateInput01 .validatePhone (phone ))
26
+ System .out .println ("Invalid phone number" );
27
+ else
28
+ System .out .println ("Valid input. Thank you." );
29
+ }
30
+ }
Original file line number Diff line number Diff line change
1
+ public class ValidateInput01
2
+ {
3
+ public static boolean validateFirstName (String firstName )
4
+ {
5
+ return firstName .matches ("[A-Z][a-zA-Z]*" );
6
+ }
7
+
8
+ public static boolean validateLastName (String lastName )
9
+ {
10
+ return lastName .matches ("[a-zA-z]+(['-][a-zA-Z]+)*" );
11
+ }
12
+
13
+ public static boolean validateAddress (String address )
14
+ {
15
+ return address .matches (
16
+ "\\ d+\\ s+([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" );
17
+ }
18
+
19
+ public static boolean validateCity (String city )
20
+ {
21
+ return city .matches ("([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" );
22
+ }
23
+
24
+ public static boolean validateState (String state )
25
+ {
26
+ return state .matches ("([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" ) ;
27
+ }
28
+
29
+ public static boolean validateZip (String zip )
30
+ {
31
+ return zip .matches ("\\ d{5}" );
32
+ }
33
+
34
+ public static boolean validatePhone (String phone )
35
+ {
36
+ return phone .matches ("[1-9]\\ d{2}-[1-9]\\ d{2}-\\ d{4}" );
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ FUTURE
2
+ Validate01.class
3
+ --string-refine
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION SUCCESSFUL$
7
+ --
8
+ ^warning: ignoring
Original file line number Diff line number Diff line change
1
+ public class Validate02
2
+ {
3
+ public static void main (String [] args )
4
+ {
5
+ String address = "ZZZ IIII AAAA 5689" ;
6
+ String city = "Oxford" ;
7
+ String state = "Oxfordshire" ;
8
+ String zip = "OX37AF" ;
9
+ String phone = "+4477777" ;
10
+
11
+ if (!ValidateInput02 .validateAddress (address ))
12
+ assert false ;
13
+ else if (!ValidateInput02 .validateCity (city ))
14
+ System .out .println ("Invalid city" );
15
+ else if (!ValidateInput02 .validateState (state ))
16
+ System .out .println ("Invalid state" );
17
+ else if (!ValidateInput02 .validateZip (zip ))
18
+ System .out .println ("Invalid zip code" );
19
+ else
20
+ System .out .println ("Valid input. Thank you." );
21
+ }
22
+ }
Original file line number Diff line number Diff line change
1
+ public class ValidateInput02
2
+ {
3
+ public static boolean validateFirstName (String firstName )
4
+ {
5
+ return firstName .matches ("[A-Z][a-zA-Z]*" );
6
+ }
7
+
8
+ public static boolean validateLastName (String lastName )
9
+ {
10
+ return lastName .matches ("[a-zA-z]+(['-][a-zA-Z]+)*" );
11
+ }
12
+
13
+ public static boolean validateAddress (String address )
14
+ {
15
+ return address .matches (
16
+ "\\ d+\\ s+([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" );
17
+ }
18
+
19
+ public static boolean validateCity (String city )
20
+ {
21
+ return city .matches ("([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" );
22
+ }
23
+
24
+ public static boolean validateState (String state )
25
+ {
26
+ return state .matches ("([a-zA-Z]+|[a-zA-Z]+\\ s[a-zA-Z]+)" ) ;
27
+ }
28
+
29
+ public static boolean validateZip (String zip )
30
+ {
31
+ return zip .matches ("\\ d{5}" );
32
+ }
33
+
34
+ public static boolean validatePhone (String phone )
35
+ {
36
+ return phone .matches ("[1-9]\\ d{2}-[1-9]\\ d{2}-\\ d{4}" );
37
+ }
38
+ }
Original file line number Diff line number Diff line change
1
+ FUTURE
2
+ Validate02.class
3
+ --string-refine
4
+ ^EXIT=0$
5
+ ^SIGNAL=0$
6
+ ^VERIFICATION FAILED$
7
+ --
8
+ ^warning: ignoring
You can’t perform that action at this time.
0 commit comments