OK, so you already have the loop described in my post earlier, all you need to do now is add the check to see whether your phone number ($data[0] by the look of it) is exactly ten digits long (or whatever the condition(s)), and only execute the query and increment the counter if they meet that condition.
While you’re at it, might be worth upgraded to mysqli or PDO as the database calls you’re using there are no longer part of the current PHP language.
Same thing - your validation function would just check that the numbers start correctly and return true or false, and your main loop would look at the return from the function to decide whether to insert them into the database or not.