0

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.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by as.bhanuprakash
0

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.