2015-05-27 7 views
8

मान्य करने वाली नियमित अभिव्यक्ति मैंने पैन रेगेक्स के लिए this question और this blog देखा है। [A-Z]{5}[0-9]{4}[A-Z]{1}। लेकिन मेरा सवाल उससे थोड़ा अधिक विस्तारित है।पैन कार्ड नंबर

पैन कार्ड नंबर में:

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. 

मैं regex उस के आधार पर जाँच करना चाहते हैं। चूंकि मुझे व्यक्ति का नाम मिलता है, या किसी अन्य संपादन टेक्स्ट में संगठन, मुझे चौथी और 5 वें पत्र को आगे सत्यापित करने की आवश्यकता होती है।

यह पता चला होने के लिए [A-Z]{3}[C,H,F,A,T,B,L,J,G,P]{1}**something for the fifth character**[0-9]{4}[A-Z]{1}

मैं यह पता लगाने की कैसे कि कुछ है लिखा जा नहीं पा रहा हूँ।

प्रोग्रामेटिक रूप से, यह किया जा सकता है, someone has done it in rails लेकिन क्या यह रेगेक्स के माध्यम से किया जा सकता है? कैसे?

+1

आप ([सी, एच, एफ, ए, टी, बी, एल, जे, जी] पी) की कोशिश की थी। कितने अक्षर मौजूद हैं? –

+0

को समझने में सक्षम नहीं कर सकते | –

+0

@ अवीशशराज अगर पैन कार्ड नंबर में चौथा चरित्र पी है, तो पांचवां चरित्र आपके उपनाम का पहला अक्षर होगा, उदाहरण के लिए। यदि आप अविनाश राज हैं, तो आपका पैनकार्ड नंबर का चौथा चरित्र व्यक्तिगत रूप से पी होगा और पांचवां चरित्र राज का आर होगा। जबकि यदि पैन कार्ड किसी संगठन से संबंधित है, तो एक कंपनी कहें तो चौथा चरित्र कंपनी के लिए सी है और पांचवां चरित्र कंपनी के नाम का पहला अक्षर है, उदाहरण के लिए, यदि "माइक्रोसॉफ्ट कॉर्पोरेशन" नामक एक कंपनी है, तो चौथा चरित्र कंपनी के लिए "सी" होगा और माइक्रोसॉफ्ट के लिए पांचवां चरित्र "एम" होगा। – inquisitive

उत्तर

4

matches() के साथ आप जिस रेगेक्स का उपयोग कर सकते हैं वह उपयोगकर्ताओं के अतिरिक्त इनपुट के आधार पर बनाया गया है, और पिछले 4 वें चरित्र के लिए पीछे-पीछे की जांच की जाती है। 4 पत्र P है, तो हम उपनाम के पहले अक्षर के लिए जाँच, और अगर 4 पत्र P नहीं है, हम इकाई नाम के पहले अक्षर की जाँच करें:

String rx = "[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]"; 

Sample code:

String c1 = "S"; // First letter in surname coming from the EditText (with P before) 
String c2 = "F"; // First letter in name coming from another EditText (not with P before) 
String pan = "AWSPS1234Z"; // true 
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]")); 
pan = "AWSCF1234Z"; // true 
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]")); 
pan = "AWSCS1234Z"; // false 
System.out.println(pan.matches("[A-Z]{3}([CHFATBLJGP])(?:(?<=P)" + c1 + "|(?<!P)" + c2 + ")[0-9]{4}[A-Z]")); 
3 बिंदु
1

enter image description here

Pan= edittextPan.getText().toString().trim(); 

Pattern pattern = Pattern.compile("[A-Z]{5}[0-9]{4}[A-Z]{1}"); 

Matcher matcher = pattern .matcher(Pan); 

if (matcher .matches()) { 
Toast.makeText(getApplicationContext(), Pan+" is Matching", 
Toast.LENGTH_LONG).show(); 

} 
else 
{ 
Toast.makeText(getApplicationContext(), Pan+" is Not Matching", 
Toast.LENGTH_LONG).show(); 
} 
संबंधित मुद्दे