answersLogoWhite

0

It depends what you mean by validation. If you mean the actual phone number itself, the best you can do is count the digits to ensure it is the correct length. But that will only tell that it could be a phone number, not that it is a phone number. You'd have to dial the number to check its actual validity.

If you actually mean the 15-digit IMEI number, that can be easily validated. The final digit (#15) is a checksum digit. To validate the IMEI, double every second digit. If the product is greater than 10, subtract 9 (same as adding the two digits together). Finally add all 15 digits together. If the sum is divisible by 10, the number is a valid IMEI number. An example implementation is shown:

#include

int main()

{

int IMEI[15];

int i = 0;

int sum = 0;

char cIMEI[16];

memset( &cIMEI[0], 0, 16 );

while( strlen( cIMEI ) != 15 )

{

std::cout << "Enter the 15-digit IMEI number: ";

std::cin.getline( cIMEI, 16, '\n' );

}

// Convert characters to integers (digits).

for( i=0; i<15; ++i)

IMEI[i] = (int) ( cIMEI[i] - '0');

// Iterate the digits.

for( i=0; i<15; ++i)

{

// For odd elements only (every 2nd digit).

if( i % 2 )

{

IMEI[i] *= 2; // Double the digit.

if( IMEI[i] > 9 ) // Is the product 10, 12, 14, 16 or 18?

IMEI[i] -= 9; // Add the 2 individual digits together.

}

// Update the sum.

sum += IMEI[i];

}

// Display the result:

std::cout << "The IMEI number is ";

if( sum % 10)

std::cout << "invalid!" << std::endl;

else

std::cout << "valid!" << std::endl;

return( 0 );

}

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

How is validation done?

Validation is done in various ways. This is an act of confirmation and be done through counter checking or comparing various resources.


How can you use validation in a sentence?

The figures needed validation before the accounts could be done.


What stage of testing is field level validation done?

in system level stage field level validation down.


How do you write mobile number 9018289011 in numeric?

Just as you have done in the question.


What is batch validation in clinical data management?

batch validation is a programmed validation to achieve valid data. its done after data entry and before data cleaning. batch validation can be over night process or day process.


How do you log into facebook using mobile number?

It is simply done by integrating your cell phone number with your profile account.


Is Programming a language?

No, but of course there is a programmers' slang. And programming is done with so-called 'programming languages'.


What is monarch programming?

Computer programming done by Kings and Queens. Very rare.


How does form validation differ in JavaScript and PHP?

In JavaScript the validation is done client side, which means it can be easily bypassed by turning JavaScript off in your browser. But with PHP it is server side, which means you can't switch it off, so you can't bypass the validation.


What are similarity and difference between conventional programming and AI programming?

Conventional is done by hand and is much slower AI is done by machine and is 100times


How is client side validation carried out?

Generally client side validation uses functions or a validation object and methods to check that a user has entered valid data, and that all required data is entered. Validation for text fields is often done by attaching a function call to the "blur" event of the text element. Validating that all required data is present is normally done by attaching an event to the "submit" event on the form. In all cases, you have to be aware that client side validation is only useful for user experience. It cannot be relied on, and so even with it, server side validation has to be done on the submitted data. This is true even in cases where AJAX is employed, as all client side code is suspect.


What activities are done during the coding phase?

programming