Experience summary of using ivx to parse ID card number

Today we are going to make a demo. The user only needs to enter the ID number to get the user's birthday and age, and calculate how many days are left until the user's next birthday. The demo mainly uses string segmentation and function components. The following are the specific implementation steps.
Experience summary of using ivx to parse ID card number
1. The result of the calculation in the demo is stored in a common variable. We directly bind the three text components responsible for displaying the result with the common variable.
Experience summary of using ivx to parse ID card number
2. After clicking the button, first determine whether the input content of the input box is an ID number, if not, then prompt the user to verify.
Experience summary of using ivx to parse ID card number
3. If the input content is an ID number, extract the information from it and assign it to a common variable. The 7-14 digits of the ID number are the date of birth, 7-10 digits are the year, 11-12 digits are the month, and 13-14 digits are the date. So use the slice method to extract the year, month, and day, and then splice them into the birthday element of the common variable in yyyy-mm-dd format. In addition, subtract the extracted year from the current date year to get the user's age. We will It is stored in the age element of the common variable.
Experience summary of using ivx to parse ID card number
Experience summary of using ivx to parse ID card number
4. The next step is to calculate the number of days before the next birthday of the user through the function component. The receiving parameter of the function is the input ID number.
The first step is to use the year of this year plus the month and date in the ID number to stitch the user's birthday date in the format of yyyy-mm-dd, and then obtain the time stamp of this date (time stamp refers to Greenwich time 1970 The total number of milliseconds from January 01, 00:00:00 (Beijing time, January 1, 1970, 08:00:00) to the present).
The second step is the same, splicing out the date of the day in yyyy-mm-dd format and obtaining its timestamp.
The third step is to make a judgment based on the previous two timestamps. If the timestamp of the current day ’s date is smaller, it means that the user has not had a birthday this year, and then directly subtract the current day ’s timestamp from this year ’s birthday datestamp, and then convert the result. It can be calculated by taking the day as the unit, otherwise, the user ’s birthday date next year will be stitched together and the time stamp will be obtained and then the current date time stamp will be subtracted. (Demo does not deal with the birthday on February 29th of the leap year, you can add your own logic)
Experience summary of using ivx to parse ID card number
5. Finally, use the result of the calculation as the return parameter of the function and assign it to the birthdayCount element of the general variable in the callback of the function.
Experience summary of using ivx to parse ID card number
In summary
, the content of the function component part can also be written in an action group. The date in yyyy-mm-dd format is a string, which can be stored in a text variable, and the time stamp can be stored in a numeric variable. In addition, the current action group setting returns The resulting action is similar to the return in the function. Here is a simple demonstration. You can try the rest. You can finally call it like the function component and get the calculation result in the callback.
Experience summary of using ivx to parse ID card number
Experience summary of using ivx to parse ID card number

Guess you like

Origin blog.51cto.com/14556317/2486042