Home  >  Article  >  Backend Development  >  A commonly used regular expression verification class_PHP tutorial

A commonly used regular expression verification class_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:08:03898browse

A commonly used regular expression verification class

A regular expression verification tool class written a long time ago, including some common checksums and supporting custom regular expressions Match, you can choose to match exactly or get all matches. I once used it to write a tool that imitated the regular expression plug-in under Eclispe. Because a few friends have suddenly been asking questions in this regard recently, I might as well post the code.

using System;
02.using System.Collections;
03.using System.Text.RegularExpressions;
04.
05.namespace Xrinehart.Framework.Common.Validate
06.{
07. /**////


08. /// RegularMatch 的摘要说明。
09. ///

10. public class RegularMatch
11. {
12. private string _String;
13. private bool _IsEntirety;
14.
15. /**////
16. /// Types that can be judged
17. ///

18. public enum operation
19. {
20. Byte, SByte, Int16, Int32, Int64, Single, Double, Boolean, Char, Decimal, DateTime, Date, Time,
21. EMail, URL, ChinaPhone, ChineseWord, ChinesePostalCode, Number, StringModel_01, StringModel_02, WideWord, NarrowWord, IPAddress,
22. ChineseMobile, ChineseID
23. };
24.
25. public RegularMatch() { }
26.
27. Used to determine whether a string is of the corresponding type (the default is to include matching) #region is used to determine whether the string is of the corresponding type (the default is to include matching)
28. public bool IsAccordType(string strVerifyString, Operation op)
29. {
30. return IsAccordType(strVerifyString, op, false);
31. }
32. #endregion
33.
34. Used to determine whether a string is of the corresponding type (or whether it contains characters of the corresponding type) #region Used to determine whether a string is of the corresponding type (or whether it contains characters of the corresponding type)
35. /**////
36. /// Used to determine whether a string is of the corresponding type
37. ///

38. /// String, the string to be judged
39. /// Operation enumeration, used to select the operation to be performed
40. /// Boolean, determine whether it is an exact match or contains a matching pattern (only applicable to non-type judgment)
41. ///
42. public bool IsAccordType(string strVerifyString, Operation op, bool IsEntirety)
43. {
44. _String = strVerifyString;
45. _IsEntirety = IsEntirety;
46.
47. switch (op)
48. {
49. case Operation.Byte:
50. {
51. return IsByte();
52. }
53. case Operation.SByte:
54. {
55. return IsSByte();
56. }
57. case Operation.Int16:
58. {
59. return IsInt16();
60. }
61. case Operation.Int32:
62. {
63. return IsInt32();
64. }
65. case Operation.Int64:
66. {
67. return IsInt64();
68. }
69. case Operation.Single:
70. {
71. return IsSingle();
72. }
73. case Operation.Double:
74. {
75. return IsDouble();
76. }
77. case Operation.Boolean:
78. {
79. return IsBoolean();
80. }
81. case Operation.Char:
82. {
83. return IsChar();
84. }
85. case Operation.Decimal:
86. {
87. return IsDecimal();
88. }
89. case Operation.DateTime:
90. {
91. return IsDateTime();
92. }
93. case Operation.Date:
94. {
95. return IsDate();
96. }
97. case Operation.Time:
98. {
99. return IsTime();
100. }
101. case Operation.IPAddress:
102. {
103. return IsIPAddress();
104. }
105. case Operation.ChinaPhone:
106. {
107. return IsChinaPhone();
108. }
109. case Operation.ChinesePostalCode:
110. {
111. return IsChinesePostalCode();
112. }
113. case Operation.ChineseMobile:
114. {
115. return IsChineseMobile();
116. }
117. case Operation.EMail:
118. {
119. return IsEmail();
120. }
121. case Operation.URL:
122. {
123. return IsURL();
124. }
125. case Operation.ChineseWord:
126. {
127. return IsChineseWord();
128. }
129. case Operation.Number:
130. {
131. return IsNumber();
132. }
133. case Operation.StringModel_01:
134. {
135. return IsStringModel_01();
136. }
137. case Operation.StringModel_02:
138. {
139. return IsStringModel_02();
140. }
141. case Operation.WideWord:
142. {
143. return IsWideWord();
144. }
145. case Operation.NarrowWord:
146. {
147. return IsNarrowWord();
148. }
149. case Operation.ChineseID:
150. {
151. return IsChineseID();
152. }
153. default:
154. {
155. return false;
156. }
157. }
158. }
159. #endregion
160.
161. Specific verification method #region Specific verification method
162.
163. Whether Byte type (8-bit unsigned integer): unsigned integer between 0 and 255 #region Whether Byte type (8-bit unsigned integer): unsigned integer between 0 and 255
164. /**////
165. /// Whether it is Byte type (8-bit unsigned integer): unsigned integer between 0 and 255
166. ///

167. /// Boolean
168. protected bool IsByte()
169. {
170. try
171. {
172. Byte.Parse(_String);
173. }
174. catch
175. {
176. return false;
177. }
178. return true;
179. }
180. #endregion
181.
182. Whether it is SByte type (8-bit signed integer): an integer between -128 and +127#region Whether it is SByte type (8-bit signed integer): an integer between -128 and +127
183. /**////
184. /// Whether it is SByte type (8-bit signed integer): an integer between -128 and +127
185. ///

186. /// Boolean
187. protected bool IsSByte()
188. {
189. try
190. {
191. SByte.Parse(_String);
192. }
193. catch
194. {
195. return false;
196. }
197. return true;
198. }
199. #endregion
200.
201. Whether it is an Int16 type (a 16-bit signed integer): a signed integer between -32768 and +32767 #region whether it is an Int16 type (a 16-bit signed integer): a signed integer between -32768 and +32767
202. /**////
203. /// Whether the Int16 type (16-bit signed integer): signed integer between -32768 and +32767
204. ///

205. /// Boolean
206. protected bool IsInt16()
207. {
208. try
209. {
210. Int16.Parse(_String);
211. }
212. catch
213. {
214. return false;
215. }
216. return true;
217. }
218. #endregion
219.
220. Is the Int32 type (32-bit signed integer): a signed integer between -2,147,483,648 and +2,147,483,647 #region Is it an Int32 type (32-bit signed integer): a signed integer between -2,147,483,648 and +2,147,483,647
221. /**////
222. /// Whether the Int32 type (32-bit signed integer): signed integer between -2,147,483,648 and +2,147,483,647
223. ///

224. /// Boolean
225. protected bool IsInt32()
226. {
227. try
228. {
229. Int32.Parse(_String);
230. }
231. catch
232. {
233. return false;
234. }
235. return true;
236. }
237. #endregion
238.
239. Whether the Int64 type (64-bit signed integer): -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 Integer #region Whether the Int64 type (64-bit signed integer): -9,223,372,036,854,775 , an integer between 808 and +9,223,372,036,854,775,807
240. /**////
241. /// Whether the Int64 type (64-bit signed integer): an integer between -9,223,372,036,854,775,808 and +9,223,372,036,854,775,807
242. ///

243. /// Boolean
244. protected bool IsInt64()
245. {
246. try
247. {
248. Int64.Parse(_String);
249. }
250. catch
251. {
252. return false;
253. }
254. return true;
255. }
256. #endregion
257.
258. Whether it is a Single type (single-precision (32-bit) floating-point number): Single-precision 32-bit number #region between -3.402823e38 and +3.402823e38 Whether it is a Single-type (single-precision (32-bit) floating-point number): - A single-precision 32-bit number between 3.402823e38 and +3.402823e38
259. /**////
260. /// Whether Single type (single-precision (32-bit) floating point number): single-precision 32-bit number between -3.402823e38 and +3.402823e38
261. ///

262. /// Boolean
263. protected bool IsSingle()
264. {
265. try
266. {
267. Single.Parse(_String);
268. }
269. catch
270. {
271. return false;
272. }
273. return true;
274. }
275. #endregion
276.
277. Whether it is Double type (single-precision (64-bit) floating-point number): Double-precision 64-bit number between -1.79769313486232e308 and +1.79769313486232e308 #region Whether it is Double type (single-precision (64-bit) floating-point number): - Double precision 64-bit number between 1.79769313486232e308 and +1.79769313486232e308
278. /**////
279. /// Whether Double type (single-precision (64-bit) floating point number): Double-precision 64-bit number between -1.79769313486232e308 and +1.79769313486232e308
280. ///

281. /// Boolean
282. protected bool IsDouble()
283. {
284. try
285. {
286. Double.Parse(_String);
287. }
288. catch
289. {
290. return false;
291. }
292. return true;
293. }
294. #endregion
295.
296. Whether the Boolean type (Boolean value): true or false #region Whether the Boolean type (Boolean value): true or false
297. /**////
298. /// Whether Double type (single-precision (64-bit) floating point number): Double-precision 64-bit number between -1.79769313486232e308 and +1.79769313486232e308
299. ///

300. /// Boolean
301. protected bool IsBoolean()
302. {
303. try
304. {
305. Boolean.Parse(_String);
306. }
307. catch
308. {
309. return false;
310. }
311. return true;
312. }
313. #endregion
314.
315. Whether it is Char type (Unicode (16-bit) character): The value range of this 16-bit number is from hexadecimal value 0x0000 to 0xFFFF#region Whether it is Char type (Unicode (16-bit) character): The value of this 16-bit number Values ​​range from hexadecimal values ​​0x0000 to 0xFFFF
316. /**////
317. /// Whether it is Char type (Unicode (16-bit) character): The value range of this 16-bit number is from hexadecimal value 0x0000 to 0xFFFF
318. ///

319. /// Boolean
320. protected bool IsChar()
321. {
322. try
323. {
324. Char.Parse(_String);
325. }
326. catch
327. {
328. return false;
329. }
330. return true;
331. }
332. #endregion
333.
334. Whether it is Char type (96-bit decimal value): whether the decimal number #region between positive 79,228,162,514,264,337,593,543,950,335 and negative 79,228,162,514,264,337,593,543,950,335 is Char type (96-bit decimal value) : A decimal number from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335
335. /**////
336. /// Whether it is Char type (96-bit decimal value): a decimal number between positive 79,228,162,514,264,337,593,543,950,335 and negative 79,228,162,514,264,337,593,543,950,335
337. ///

338. /// Boolean
339. protected bool IsDecimal()
340. {
341. try
342. {
343. Decimal.Parse(_String);
344. }
345. catch
346. {
347. return false;
348. }
349. return true;
350. }
351. #endregion
352.
353. Whether it is a DateTime type (representing a moment in time): The range is between 12:00:00 midnight on January 1, 0001 AD (Christian Era) to 11:59:59 pm on December 31, 9999 AD (C.E.) The date and time between #region is of DateTime type (representing a moment in time): ranging from 12:00:00 midnight on January 1, 0001 AD (Christian Era) to 11 pm on December 31, 9999 AD (C.E.) :59:59 Date and time
354. /**////
355. /// Whether it is a DateTime type (representing a moment in time): The range is from 12:00:00 midnight on January 1, 0001 AD (Christian Era) to 11:59 pm on December 31, 9999 AD (C.E.) Date and time between :59
356. ///

357. /// Boolean
358. protected bool IsDateTime()
359. {
360. try
361. {
362. DateTime.Parse(_String);
363. }
364. catch
365. {
366. return false;
367. }
368. return true;
369. }
370. #endregion
371.
372. Whether it is a Date type (the date part representing time): The date range is between January 1, 0001 AD (Christian Era) and December 31, 9999 AD (C.E.) #region Whether it is a Date type (the date part representing time) Date part): A date ranging from January 1, 0001 AD (Christian Era) to December 31, 9999 AD (C.E.)
373. /**////
374. /// Whether it is Date type (date part representing time): a date ranging from January 1, 0001 AD (Christian Era) to December 31, 9999 AD (C.E.)
375. ///

376. /// Boolean
377. protected bool IsDate()
378. {
379. DateTime Value;
380. try
381. {
382. Value = DateTime.Parse(_String);
383. }
384. catch
385. {
386. return false;
387. }
388. if (Value.Date.ToString() == _String)
389. {
390. return true;
391. }
392. else
393. {
394. return false;
395. }
396. }
397. #endregion
398.
399. Whether it is a Time type (representing the time part HHMMSS): The range is between 12:00:00 pm and 11:59:59 pm#region Whether it is a Time type (representing the time part HHMMSS): The range is 12:00 pm: Time between 00 and 11:59:59 pm
400. /**////
401. /// Whether it is Time type (indicating the time part HHMMSS): The range is between 12:00:00 pm and 11:59:59 pm
402. ///

403. /// Boolean
404. protected bool IsTime()
405. {
406. DateTime Value;
407. try
408. {
409. Value = DateTime.Parse(_String);
410. }
411. catch
412. {
413. return false;
414. }
415. if (Value.Year == 1 && Value.Month == 1 && Value.Day == 1)
416. {
417. return true;
418. }
419. else
420. {
421. return false;
422. }
423. }
424. #endregion
425.
426. Whether the IPAddress type (in the case of IPv4, use the four-part notation format separated by dots, and in the case of IPv6, use colon and hexadecimal format) #region Whether the IPAddress type (in the case of IPv4, use the dot-separated notation format) expressed in four-part notation format, in the case of IPv6 using colon and hexadecimal format)
427. /**////
428. /// Whether the IPAddress type (in the case of IPv4, it is represented by a four-part notation separated by dots, and in the case of IPv6, it is represented by a colon and hexadecimal format)
429. ///

430. /// Boolean
431. protected bool IsIPAddress()
432. {
433. try
434. {
435. System.Net.IPAddress.Parse(_String);
436. }
437. catch
438. {
439. return false;
440. }
441. return true;
442. }
443. #endregion
444.
445. Is the Chinese phone number type (XXX/XXXX-XXXXXXX/XXXXXXXX (/d{3,4})-?/d{7,8}): Determine whether it is (area code: 3 or 4 digits)-(phone number : 7 or 8 digits) #region Whether the Chinese phone number type (XXX/XXXX-XXXXXXX/XXXXXXXX (/d{3,4})-?/d{7,8}): Determine whether it is (area code: 3 or 4 digits) - (phone number: 7 or 8 digits)
446. /**////
447. /// Is the Chinese phone number type (XXX/XXXX-XXXXXXX/XXXXXXXX (/d{3,4})-?/d{7,8}): Determine whether it is (area code: 3 or 4 digits)- (Phone number: 7 or 8 digits)
448. ///

449. /// Boolean
450. protected bool IsChinaPhone()
451. {
452. ArrayList aryResult = new ArrayList();
453. return CommRegularMatch(_String, @"(/d{3,4})-?/d{7,8}", RegexOptions.None, ref aryResult, _IsEntirety);
454. }
455. #endregion
456.
457. Is the Chinese postal code (6 digits /d{6}) #region Is the Chinese postal code (6 digits /d{6})
458. /**////
459. /// Is the Chinese postal code (6 digits /d{6})
460. ///

461. /// Boolean
462. protected bool IsChinesePostalCode()
463. {
464. ArrayList aryResult = new ArrayList();
465. return CommRegularMatch(_String, @"/d{6}", RegexOptions.None, ref aryResult, _IsEntirety);
466. }
467. #endregion
468.
469. Is it a China Mobile phone number (a total of 11 digits starting with 13 13/d{9}) #region Is it a China Mobile phone number (a total of 11 digits starting with 13 13/d{9})
470. /**////
471. /// Is it a China Mobile phone number (a total of 11 digits starting with 13 13/d{9})
472. ///

473. /// Boolean
474. protected bool IsChineseMobile()
475. {
476. ArrayList aryResult = new ArrayList();
477. return CommRegularMatch(_String, @"13/d{9}", RegexOptions.None, ref aryResult, _IsEntirety);
478. }
479. #endregion
480.
481. Is the EMail type (XXX@XXX.XXX /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*)#region Whether it is an EMail type (XXX@XXX.XXX /w+([-+.]/w+)*@/w+( [-.]/w+)*/./w+([-.]/w+)*)
482. /**////
483. /// Whether the EMail type is (XXX@XXX.XXX /w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*)
484. ///

485. /// Boolean
486. protected bool IsEmail()
487. {
488. ArrayList aryResult = new ArrayList();
489. return CommRegularMatch(_String, @"/w+([-+.]/w+)*@/w+([-.]/w+)*/./w+([-.]/w+)*", RegexOptions. None, ref aryResult, _IsEntirety);
490. }
491. #endregion
492.
493. Whether the Internet URL address type (http://) #region whether the Internet URL address type (http://)
494. /**////
495. /// Whether the Internet URL address type (http://)
496. ///

497. /// Boolean
498. protected bool IsURL()
499. {
500. ArrayList aryResult = new ArrayList();
501. return CommRegularMatch(_String, @"http://([/w-]+/.)+[/w-]+(/[/w- ./?%&=]*)?", RegexOptions. None, ref aryResult, _IsEntirety);
502. }
503. #endregion
504.
505. Whether it contains Chinese characters ([/u4e00-/u9fa5]) #region Whether it contains Chinese characters ([/u4e00-/u9fa5])
506. /**////
507. /// Whether it is Chinese characters ([/u4e00-/u9fa5])
508. ///

509. /// Boolean
510. protected bool IsChineseWord()
511. {
512. ArrayList aryResult = new ArrayList();
513. return CommRegularMatch(_String, @"[/u4e00-/u9fa5]", RegexOptions.None, ref aryResult, _IsEntirety);
514. }
515. #endregion
516.
517. Whether it is a number (a number from 0 to 9 [/d]+): does not include the symbols "." and "-" #region Whether it is a number (a number from 0 to 9 [/d]+): does not include the symbol " ."and"-"
518. /**////
519. /// Whether it is a number (numbers from 0 to 9[/d]+): excluding the symbols "." and "-"
520. ///

521. /// Boolean
522. protected bool IsNumber()
523. {
524. ArrayList aryResult = new ArrayList();
525. return CommRegularMatch(_String, @"[/d]+", RegexOptions.None, ref aryResult, _IsEntirety);
526. }
527. #endregion
528.
529. Whether to contain only numbers, English and underscores ([/w]+) #region Whether to contain only numbers, English and underscores ([/w]+)
530. /**////
531. ///Whether it only contains numbers, English and underscores ([/w]+)
532. ///

533. /// Boolean
534. protected bool IsStringModel_01()
535. {
536. ArrayList aryResult = new ArrayList();
537. return CommRegularMatch(_String, @"[/w]+", RegexOptions.None, ref aryResult, _IsEntirety);
538. }
539. #endregion
540.
541. Whether to capitalize the first letter of English letters ([A-Z][a-z]+) #region Whether to capitalize the first letter of English letters ([A-Z][a-z]+)
542. /**////
543. /// Whether to capitalize the first letter of the English letter ([A-Z][a-z]+)
544. ///

545. /// Boolean
546. protected bool IsStringModel_02()
547. {
548. ArrayList aryResult = new ArrayList();
549. return CommRegularMatch(_String, @"[A-Z][a-z]+", RegexOptions.None, ref aryResult, _IsEntirety);
550. }
551. #endregion
552.
553. Whether full-width characters ([^/x00-/xff]): including Chinese characters #region Whether full-width characters ([^/x00-/xff]): including Chinese characters
554. /**////
555. /// Whether full-width characters ([^/x00-/xff]): including Chinese characters
556. ///

557. /// Boolean
558. protected bool IsWideWord()
559. {
560. ArrayList aryResult = new ArrayList();
561. return CommRegularMatch(_String, @"[^/x00-/xff]", RegexOptions.None, ref aryResult, _IsEntirety);
562. }
563. #endregion
564.
565. Whether it is a half-width character ([/x00-/xff]) #region Whether it is a half-width character ([/x00-/xff])
566. /**////
567. /// Whether half-width characters ([^/x00-/xff]): including Chinese characters
568. ///

569. /// Boolean
570. protected bool IsNarrowWord()
571. {
572. ArrayList aryResult = new ArrayList();
573. return CommRegularMatch(_String, @"[/x00-/xff]", RegexOptions.None, ref aryResult, _IsEntirety);
574. }
575. #endregion
576.
577. Is the Chinese ID number valid? #region Is the Chinese ID number legal?
578. protected bool IsChineseID()
579. {
580. if (_String.Length == 15)
581. {
582. _String = CidUpdate(_String);
583. }
584. if (_String.Length == 18)
585. {
586. string strResult = CheckCidInfo(_String);
587. if (strResult == "Illegal area" || strResult == "Illegal birthday" || strResult == "Illegal certificate number")
588. {
589. return false;
590. }
591. else
592. {
593. return true;
594. }
595. }
596. else
597. {
598. return false;
599. }
600. }
601. #endregion
602.
603. #endregion
604.
605. Universal regular expression judgment function#region Universal regular expression judgment function
606. /**////
607. /// General regular expression judgment function
608. ///

609. /// String, string used for matching
610. /// String, regular expression
611. /// RegexOptions, configure regular expression options
612. /// ArrayList, decomposed string content
613. /// Boolean, whether an exact match is required
614. ///
615. public bool CommRegularMatch(string strVerifyString, string strRegular, System.Text.RegularExpressions.RegexOptions regOption, ref System.Collections.ArrayList aryResult, bool IsEntirety)
616. {
617. System.Text.RegularExpressions.Regex r;
618. System.Text.RegularExpressions.Match m;
619.
620. If an exact match is required #region If an exact match is required
621. if (IsEntirety)
622. {
623. strRegular = strRegular.Insert(0, @"/A");
624. strRegular = strRegular.Insert(strRegular.Length, @"/z");
625. }
626. #endregion
627.
628. try
629. {
630. r = new System.Text.RegularExpressions.Regex(strRegular, regOption);
631. }
632. catch (System.Exception e)
633. {
634. throw (e);
635. }
636.
637. for (m = r.Match(strVerifyString); m.Success; m = m.NextMatch())
638. {
639. aryResult.Add(m);
640. }
641.
642. if (aryResult.Count == 0)
643. {
644. return false;
645. }
646. else
647. {
648. return true;
649. }
650. }
651. #endregion
652.
653. China ID number verification #region China ID number verification
654. private string CheckCidInfo(string cid)
655. {
656. string[] aCity = new string[] { null, null, null, null, null, null, null, null, null, null, null, "Beijing", "Tianjin", "Hebei", "Shanxi", "Inner Mongolia", null, null, null, null, null, "Liaoning", "Jilin", "Heilongjiang", null, null, null, null, null, null, null, "Shanghai", "Jiangsu", "Zhejiang" ", "Anwei", "Fujian", "Jiangxi", "Shandong", null, null, null, "Henan", "Hubei", "Hunan", "Guangdong", "Guangxi", "Hainan", null , null, null, "Chongqing", "Sichuan", "Guizhou", "Yunnan", "Tibet", null, null, null, null, null, null, "Shaanxi", "Gansu", "Qinghai", " Ningxia", "Xinjiang", null, null, null, null, null, "Taiwan", null, null, null, null, null, null, null, null, null, "Hong Kong", "Macau", null, null , null, null, null, null, null, null, "foreign" };
657. double iSum = 0;
658. string info = string.Empty;
659. System.Text.RegularExpressions.Regex rg = new System.Text.RegularExpressions.Regex(@"^/d{17}(/d|x)$");
660. System.Text.RegularExpressions.Match mc = rg.Match(cid);
661. if (!mc.Success)
662. {
663. return string.Empty;
664. }
665. cid = cid.ToLower();
666. cid = cid.Replace("x", "a");
667. if (aCity[int.Parse(cid.Substring(0, 2))] == null)
668. {
669. return "illegal area";
670. }
671. try
672. {
673. DateTime.Parse(cid.Substring(6, 4) + " - " + cid.Substring(10, 2) + " - " + cid.Substring(12, 2));
674. }
675. catch
676. {
677. return "Illegal birthday";
678. }
679. for (int i = 17; i >= 0; i--)
680. {
681. iSum += (System.Math.Pow(2, i) % 11) * int.Parse(cid[17 - i].ToString(), System.Globalization.NumberStyles.HexNumber);
682. }
683. if (iSum % 11 != 1)
684. {
685. return ("illegal certificate number");
686. }
687. else
688. {
689. return (aCity[int.Parse(cid.Substring(0, 2))] + "," + cid.Substring(6, 4) + "-" + cid.Substring(10, 2) + "-" + cid.Substring(12, 2) + "," + (int.Parse(cid.Substring(16, 1)) % 2 == 1 ? "Male" : "Female"));
690. }
691. }
692. #endregion
693.
694. ID card number 15 is upgraded to 18 digits#region ID card number 15 is upgraded to 18 digits
695. private string CidUpdate(string ShortCid)
696. {
697. char[] strJiaoYan = { '1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2 ' };
698. int[] intQuan = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
699. string strTemp;
700. int intTemp = 0;
701.
702. strTemp = ShortCid.Substring(0, 6) + "19" + ShortCid.Substring(6);
703. for (int i = 0; i <= strTemp.Length - 1; i++)
704. {
705. intTemp += int.Parse(strTemp.Substring(i, 1)) * intQuan[i];
706. }
707. intTemp = intTemp % 11;
708. return strTemp + strJiaoYan[intTemp];
709. }
710. #endregion
711. }
712.}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953965.htmlTechArticleA commonly used regular expression verification class. A regular expression verification tool class written a long time ago, including some common The checksum supports custom regular expression matching, which can be selected...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn