How to validiating mobile number in csv file?

hii Good Afternoon FRIENDS…
Can anyone tell while uploading CSV.FILE, how to check valid mobile num & how to count the numbers…
Anyone tell how to check plzzzzzzz…

Hi,
You have to provide some more details about your task.
What format do you use and so on

It would also help if we could know what your skill level is, and what you have done so far to try and come up with a solution for yourself.

While uploading CSV file to the database it should check only MOBILE NUMBERS & it should count how many numbers it uploaded…

How far have you got with your script?

Also you’ll need to know exactly how to define what a valid mobile number is. For example I believe here in the UK a valid mobile number always starts with “07”, but that might not be the case where you are.

But basically, start with some code to upload the CSV file, get that working and then start adding in your validation. Counting the number of valid and rejected imports won’t be a problem. Basically a pseudo-code would look something like

open file
loop until end of file {
  get next record
  check for valid mobile number format
  if it's valid {
    insert record into database
    increment counter
    }
  else
    {
    increment "reject" counter
    }
  }

In Australia they always start with “04”.

In Saudi Arabia, it’s always 05

Sounds doable as long as you can adequately distinguish what qualifies as a mobile number.
Some examples of numbers that are currently working and some that aren’t is needed.
As is the code you have right now. Not necessarily all of it, but enough to show the problem areas.

In INDIA mobile starts from 09 or 07 or 08…

I Italy a mobile number starts with 3

@shammu, I must admit, I’m not really sure where this thread is going now; it just seems to be acquiring an ever growing list of mobile number prefixes for various countries, whilst doing nothing to address your original question. Does @droopsnoot’s response answer your question, or do you still need something more? If it’s the latter, then you’ll need to come back on some of the questions asked earlier on to help you further, that primarily being, “What code do you have so far?”.

1 Like

I am curious to know the source of the Csv file.

This code for only uploading CSV.file. When i upload csv file, it must check only mobile numbers (it should not take any landline numbers & space & less mobile num. It must take only 10numbers) & it must count how many num are their.

<?php
//connect to the database 
$connect = mysql_connect("localhost", "root", "1234");
mysql_select_db("mydatabase", $connect); //select the table 
// 

if ($_FILES[csv][size] > 0) {

    //get the csv file 
    $file = $_FILES[csv][tmp_name];
    $handle = fopen($file, "r");

    //loop through the csv file and insert into database 
    do {
        if ($data[0]) {
            mysql_query("INSERT INTO contacts (contact_num) VALUES 
                ( 
                    '" . addslashes($data[0]) . "'
                ) 
            ");
        }
    } while ($data = fgetcsv($handle, 1000, ",", "'"));
    // 
    //redirect 
    header('Location: csvfile.php?success=1');
    die;
}
?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
        <title>Import a CSV File</title> 
    </head> 

    <body> 

<?php if (!empty($_GET[success])) {
    echo "<b>Your file has been imported.</b><br><br>";
} //generic success notice  ?> 

        <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
            Choose your file: <br /> 
            <input name="csv" type="file" id="csv" /> 
            <input type="submit" name="Submit" value="Submit" /> 
        </form> 

    </body> 
</html>

Easy enough to reject number sequences containing spaces and those that aren’t exactly ten digits.
What is the criteria for discriminating between mobile and landline numbers?

landline number :08182246355
Mobile number :9662241530

Sir.
it should not take below 10 digits number & space all must reject that types of numbers.

So landlines always have exactly 10 digits and mobile numbers always have exactly 9 digits?

Sir
Mobile numbers only 10 digits number

So this should be the reverse?

To be clear then Mobile numbers are always exactly 10 digits, never more and never less.
And no other numbers except for only mobiles will be 10 digits.