-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringUtil.java
45 lines (36 loc) · 1.29 KB
/
StringUtil.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
package technology.touchmars.util;
import technology.touchmars.model.WalletType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtil {
public static final String EMAIL_REGEXP =
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
public static final String PHONE_REGEXP = "\\+?^[0-9\\-]*$";
public static boolean isValidEmail(String email){
if (email==null)
return false;
Pattern pattern = Pattern.compile(EMAIL_REGEXP);
Matcher m = pattern.matcher(email.trim());
return m.matches();
}
public static boolean isValidPhone(String phone){
if (phone==null)
return false;
Pattern pattern = Pattern.compile(PHONE_REGEXP);
Matcher m = pattern.matcher(phone.trim());
return m.matches();
}
public static boolean notEmpty(String s) {
return s!=null && s.trim().length()>0;
}
public static WalletType convertString2WalletType(String s) {
if (s==null)
return null;
if (s.equals(WalletType.PAYPAL.name()))
return WalletType.PAYPAL;
else if (s.equals(WalletType.VENMO.name()))
return WalletType.VENMO;
else
return null;
}
}