How to use regular expression to judge mobile phone number and license plate number in Android
How to use regular expression to judge mobile phone number and license plate number in Android, aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
The 170 code segment of the third-party operator
Add: Unicom 4G 176, China Telecom 4G 177, Mobile 4G 178
The regular expression functions written based on these are as follows:
Public static boolean isMobileNO (String mobiles) {String telRegex = "\\ d {} | []\ d {}"; if (TextUtils.isEmpty (mobiles)) return false; else return mobiles.matches (telRegex);}
Where:
"13\ d {9}" means that the first two digits are 1 and 3, followed by any 9 digits
"14 [57]\ d {8}" means that the first two digits are 1 and 4, the third is 5 or 7, followed by any 8 digits.
and so on.
License plate number
The regular expression of the license plate number has been online all the time, but it hasn't changed much:
Public static boolean isCarnumberNO (String carnumber) {/ * license plate number format: Chinese character + Amurz + bit Amurz or-(only ordinary license plate numbers, trainer cars and some army vehicles are not included) * / String carnumRegex = "[\ ue-\ ufa] {} [Amurz] {} [Amurz -] {}"; if (TextUtils.isEmpty (carnumber)) return false Else return carnumber.matches (carnumRegex);}
Of course, this regular expression has limitations, such as the first bit is only limited to Chinese characters, there are only 34 provincial Chinese character abbreviations; the license plate number does not have the letters I and O, to prevent confusion with 1, 0; some license plates can not be distinguished, and so on.
This is the answer to the question about how to use regular expressions to judge mobile phone numbers and license plate numbers in Android. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.