16

"ABCDE1234F" のような pan カードの edittext の検証を確認する方法。これの検証を確認する方法がわかりません。みんな助けてください。どんな種類の助けにも感謝します。

4

16 に答える 16

41

パターンマッチングで正規表現を使用できます

String s = "ABCDE1234F"; // get your editext value here
Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}");
   
Matcher matcher = pattern.matcher(s);
// Check if pattern matches 
if (matcher.matches()) {
  Log.i("Matching","Yes");
}   

// [A-Z]{5} - match five literals which can be A to Z
// [0-9]{4} - followed by 4 numbers 0 to 9
// [A-Z]{1} - followed by one literal which can A to Z

正規表現 @ をテストできます

http://java-regex-tester.appspot.com/

http://docs.oracle.com/javase/tutorial/essential/regex/

アップデート

完全な別の anser 5 文字目のPAN カード番号を検証する正規表現は 4 文字目に依存します。

于 2013-07-16T18:49:14.880 に答える
10

@Raghunandanは正しいです。正規表現を使用できます。Permanent_account_number(India)の wiki エントリを参照すると、PAN カード番号の構成の意味がわかります。パターンを使用して、その有効性を確認できます。関連する部分は次のとおりです。

PAN structure is as follows: AAAAA9999A: First five characters are letters, next 4 numerals, last character letter.

1) The first three letters are sequence of alphabets from AAA to zzz
2) The fourth character informs about the type of holder of the Card. Each assesse is unique:`

    C — Company
    P — Person
    H — HUF(Hindu Undivided Family)
    F — Firm
    A — Association of Persons (AOP)
    T — AOP (Trust)
    B — Body of Individuals (BOI)
    L — Local Authority
    J — Artificial Judicial Person
    G — Government


3) The fifth character of the PAN is the first character
    (a) of the surname / last name of the person, in the case of 
a "Personal" PAN card, where the fourth character is "P" or
    (b) of the name of the Entity/ Trust/ Society/ Organisation
in the case of Company/ HUF/ Firm/ AOP/ BOI/ Local Authority/ Artificial Jurdical Person/ Govt,
where the fourth character is "C","H","F","A","T","B","L","J","G".

4) The last character is a alphabetic check digit.

`

お役に立てれば。

于 2013-07-16T18:49:25.880 に答える
0

パンカード検証の正規表現:

/(^([a-zA-Z]{5})([0-9]{4})([a-zA-Z]{1})$)/
于 2014-03-07T06:53:47.730 に答える
0

これまでに利用可能な他の回答はどれもPANチェックディジットを検証していないことに注意してください。

http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Javaからの Luhn アルゴリズムは次のとおりです。

public static boolean luhnTest(String number) {
    int s1 = 0, s2 = 0;
    String reverse = new StringBuffer(number).reverse().toString();
    for (int i = 0 ; i < reverse.length(); i++){
        int digit = Character.digit(reverse.charAt(i), 10);
        if (i % 2 == 0) { //this is for odd digits, they are 1-indexed in the algorithm
            s1 += digit;
        } else { //add 2 * digit for 0-4, add 2 * digit - 9 for 5-9
            s2 += 2 * digit;
            if (digit >= 5) {
                s2 -= 9;
            }
        }
    }
    return (s1 + s2) % 10 == 0;
}
于 2015-09-04T08:40:22.957 に答える
0

C#でのPANカード検証にキープレスイベントを使用できます

enter code here

private void textBox1_KeyPress(オブジェクト送信者, KeyPressEventArgs e)

    {           
        int sLength = textBox1.SelectionStart;  

        switch (sLength)
        {
            case 0:

            case 1:

            case 2:

            case 3:

            case 4:

                    if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                    break;

            case 5:

            case 6:

            case 7:

            case 8:
                    if (char.IsNumber(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                    break;
            case 9:
                    if (char.IsLetter(e.KeyChar) || Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        if (Char.IsControl(e.KeyChar))
                        {
                            e.Handled = false;
                        }

                        else
                        {
                            e.Handled = true;
                        }
                    }
                    break;
            default:
                    if (Char.IsControl(e.KeyChar))
                    {
                        e.Handled = false;
                    }

                    else
                    {
                        e.Handled = true;
                    }
                    break;
        }
    }
于 2014-07-21T05:41:37.330 に答える
0

適切な形式の検証は、次の正規表現で行う必要があります。

/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/

他の回答との違いは、これは 4 番目の文字が特定の値しかとれないことを考慮に入れていることです。正規表現全体は、大文字と小文字を区別しないように簡単に変更できます。

一方、このチェックはあまりにも一般的であり、最後のチェック文字の適切な検証式は、数字または文字がどの位置にあるかをチェックするだけよりもはるかに優れています. 残念ながら、この式は公開されていないようです。

于 2017-06-29T20:38:41.960 に答える
-1
^([a-zA-Z]){5}([0-9]){4}([a-zA-Z]){1}?$/

これを試してください、うまくいくことを願っています

于 2016-11-11T11:09:27.550 に答える
-1

シンプルなコンセプトを使用した非常にシンプル。

long l = System.currentTimeMillis();

String s = l + "";
String s2 = "";

System.out.println(s.length());

for (int i = s.length() - 1; i > 8; i--) {
    s2+=s.charAt(i);
} 

String pancardNo = "AVIPJ" + s2 + "K";
System.out.println(pancardNo);

この一意の pancard no をテスト目的で使用します。

于 2016-04-27T14:16:31.863 に答える