Hi All,

I need to validate the telephone number entered by the user in a form.
Following are the conditions.

1. The length of the string should be 10.
2. The first character should be ZERO.
3. Remaining 9 characters can be any digits from 1-9.

I am using the following code snippet to validate the user entry.

<?php
$input = '0123456789';  // User input
$pattern = '/^0[1-9]{9}$/'; // Pattern match
preg_match_all($pattern,$input,$matches);

if (count($matches) > 0) {
    echo "Valid user Entry";
} else {
    echo "Invalid user Entry";
}
?>

My question is whether there is any possibility for an user to override my validation and get away with an invalid entry ?
I am not good with regular expressions. Any suggestions and comments is highly appreciated.

Thanks in advance.

My question is whether there is any possibility for an user to override my validation and get away with an invalid entry ?

No. The expression allows exactly 10 characters, of which the first MUST be a zero and the remaining nine may be any of 1...9.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.