10 ответов:
Вы можете использовать регулярное выражение с шаблоном соответствия
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Вы можете проверить регулярное выражение @
@Raghunandan прав. Вы можете использовать регулярное выражение. Если вы видите запись wiki для Permanent_account_number (India) , вы получите значение формирования номера карты 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.`
Надеюсь, это поможет.
Вы можете использовать событие нажатия клавиши для проверки карты PAN в C#
enter code herePrivate void textBox1_KeyPress(object sender, 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; } }
Регулярный Exp ПАНКАРДА - '/[A-Z]{5}\d{4}[A-Z]{1} / i';
Используйте следующее, Если вы используете angular js
Контроллер
$scope.panCardRegex = '/[A-Z]{5}\d{4}[A-Z]{1}/i';HTML
<input type="text" ng-model="abc" ng-pattern="panCardRegex" />
Проверка правильного формата должна выполняться этим регулярным выражением:
Отличие от других ответов состоит в том, что здесь учитывается, что четвертая буква может принимать только определенные значения. Все регулярное выражение может быть легко изменено, чтобы быть нечувствительным к регистру.
/^[A-Z]{3}[ABCFGHLJPT][A-Z][0-9]{4}[A-Z]$/С другой стороны, эта проверка слишком универсальна, и правильная формула проверки для последней контрольной буквы была бы намного лучше, чем просто проверка, какая позиция имеет цифру или букву. Увы, эта формула, кажется, не быть общественный.
Попробуйте вот это
$(document).ready(function() { $.validator.addMethod("pan", function(value1, element1) { var pan_value = value1.toUpperCase(); var reg = /^[a-zA-Z]{3}[PCHFATBLJG]{1}[a-zA-Z]{1}[0-9]{4}[a-zA-Z]{1}$/; var pan = { C: "Company", P: "Personal", H: "Hindu Undivided Family (HUF)", F: "Firm", A: "Association of Persons (AOP)", T: "AOP (Trust)", B: "Body of Individuals (BOI)", L: "Local Authority", J: "Artificial Juridical Person", G: "Govt" }; pan = pan[pan_value[3]]; if (this.optional(element1)) { return true; } if (pan_value.match(reg)) { return true; } else { return false; } }, "Please specify a valid PAN Number"); $('#myform').validate({ // initialize the plugin rules: { pan: { required: true, pan: true } }, submitHandler: function(form) { alert('valid form submitted'); return false; } }); });<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.js"></script> <form id="myform" action="" method="post"> <div> <label>Pan Number</label> <div> <input type="text" name="pan" value="" id="input-pan" /> </div> </div> <button type="submit">Register</button> </form>
Обратите внимание, что ни один из доступных до сих пор ответов не подтверждает PAN check digit.
Вот алгоритм Луна из http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Java :
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; }
Очень просто, используя простую концепцию.
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 для тестирования .
Comments