-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStringValidator.java
75 lines (62 loc) · 2.87 KB
/
StringValidator.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
package org.jiyumana;
public class StringValidator {
public static void main(String[] args) {
String inputString = "123";
Boolean result;
Boolean result2;
//convert String to char array
char[] charArray = inputString.toCharArray();
for(int i=0; i < charArray.length; i++){
//if any character is lower case, return true
result = ( Character.isAlphabetic( charArray[i] )) ? true : false;
result2 = ( Character.isDigit( charArray[i] )) ? true : false;
if(result.equals(true)) {
break;
}
if(result2.equals(true)) {
break;
}
System.out.println("Contains any alpha numeric? : "+result);
}
for(int i=0; i < charArray.length; i++){
//if any character is lower case, return true
result = ( Character.isAlphabetic( charArray[i] )) ? true : false;
if(result.equals(true)) {
System.out.println("Contains any alphabets? : "+result);
break;
}else if(result.equals(false) && (inputString.indexOf(charArray[i]) == charArray.length -1) ) {
System.out.println("Contains any alphabets? : "+result);
}
}
for(int i=0; i < charArray.length; i++){
//if any character is lower case, return true
result = ( Character.isDigit( charArray[i] )) ? true : false;
if(result.equals(true)) {
System.out.println("contains any digit? : "+result);
break;
}else if(result.equals(false) && (inputString.indexOf(charArray[i]) == charArray.length -1) ) {
System.out.println("Contains any digit? : "+result);
}
}
for(int i=0; i < charArray.length; i++){
//if any character is lower case, return true
result = ( Character.isLowerCase( charArray[i] )) ? true : false;
if(result.equals(true)) {
System.out.println("contains any lowercase char? : "+result);
break;
}else if(result.equals(false) && (inputString.indexOf(charArray[i]) == charArray.length -1) ) {
System.out.println("Contains any lowercase? : "+result);
}
}
for(int i=0; i < charArray.length; i++){
//if any character is in upper case, return true
result = ( Character.isUpperCase( charArray[i] )) ? true : false;
if(result.equals(true)) {
System.out.println("Contains any uppercase char? : "+result);
break;
}else if(result.equals(false) && (inputString.indexOf(charArray[i]) == charArray.length -1) ) {
System.out.println("Contains any uppercase : "+result);
}
}
}
}