Possible Duplicate:
php regex , extract phone number from text/html
I have following requirement. There is a phone number field.
- Its length should be between 8 and 10
- It can contain only _ and white spaces
- First and last elements should be digits
- _ and white spaces should be in between 2 digits
Can I write a regular expression to validate the above things using php?
Example for valid entry: 231_901 347
Example for invalid entry: _123 567, 345__123
Also if possible, can you please write down the preg_match expression.
Here is the code which I tried:
$subject = "_012_345 69";
$pattern = '/[\d]{1}.[\d\s_]{5,10}.[\d]{1}$/';
$matches = preg_match($pattern, $subject);
echo($matches);
It should return 0 but it returns 1.
Explanation: