左晓为主开发手持机充值管理机
zuoxiao
2023-12-18 8226f232c39359b36aff8a9b0453c2fb48ee4372
app/src/main/java/com/dayu/recharge/activity/NewCardActivity.java
@@ -36,6 +36,8 @@
import org.json.JSONObject;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * Copyright (C), 2023,
@@ -93,7 +95,7 @@
                    if (userName.length() <= 1 || !validateName(userName)) {
                        TipUtil.show(NewCardActivity.this, "请输入正确姓名");
                        return;
                    } else if (phone.length() < 11) {
                    } else if (phone.length() < 11 || !isValidPhoneNumber(phone)) {
                        TipUtil.show(NewCardActivity.this, "请输入正确手机号");
                        return;
                    } else if (!Utils.check(userID)) {
@@ -115,6 +117,45 @@
            }
        });
    }
    private boolean isValidPhoneNumber(String phoneNumber) {
        // 定义手机号的正则表达式,确保数字部分没有连续6位相同的数字
        String phoneRegex = "^1[0-9]{10}$";
        // 创建 Pattern 对象
        Pattern pattern = Pattern.compile(phoneRegex);
        // 创建 matcher 对象
        Matcher matcher = pattern.matcher(phoneNumber);
        // 判断手机号是否匹配正则表达式
        return matcher.matches() && !hasSixConsecutiveSameDigits(phoneNumber);
    }
    /**
     * 判断是否有6个相同的连续数字
     *
     * @param input
     * @return
     */
    public static boolean hasSixConsecutiveSameDigits(String input) {
        char[] digits = input.toCharArray();
        for (int i = 0; i <= digits.length - 6; i++) {
            boolean consecutiveSame = true;
            for (int j = 1; j < 6; j++) {
                if (digits[i + j] != digits[i + j - 1]) {
                    consecutiveSame = false;
                    break;
                }
            }
            if (consecutiveSame) {
                return true;
            }
        }
        return false;
    }
    private void rxPermission() {
        PermissionX.init(NewCardActivity.this).permissions(Manifest.permission.CAMERA)
@@ -320,10 +361,11 @@
            return (c >= 0x4e00 && c <= 0x9fa5);
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        newCardActivity=null;
        newCardActivity = null;
    }
}