Is it possible to validate IMEI Number?

后端 未结 5 918
时光取名叫无心
时光取名叫无心 2021-02-09 09:40

For a mobile shop application, I need to validate an IMEI number. I know how to validate based on input length, but is their any other mechanism for validating the input number?

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-09 09:54

    A search suggests that there isn't a built-in function that will validate an IMEI number, but there is a validation method using the Luhn algorithm.

    General process:

    1. Input IMEI: 490154203237518
    2. Take off the last digit, and remember it: 49015420323751 & 8. This last digit 8 is the validation digit.
    3. Double each second digit in the IMEI: 4 18 0 2 5 8 2 0 3 4 3 14 5 2 (excluding the validation digit)
    4. Separate this number into single digits: 4 1 8 0 2 5 8 2 0 3 4 3 1 4 5 2 (notice that 18 and 14 have been split).
    5. Add up all the numbers: 4+1+8+0+2+5+8+2+0+3+4+3+1+4+5+2 = 52
    6. Take your resulting number, remember it, and round it up to the nearest multiple of ten: 60.
    7. Subtract your original number from the rounded-up number: 60 - 52 = 8.
    8. Compare the result to your original validation digit. If the two numbers match, your IMEI is valid.

    The IMEI given in step 1 above is valid, because the number found in step #7 is 8, which matches the validation digit.

提交回复
热议问题