I'm using the following regex to make sure a valid phone number has been entered. If there are more than 10 digits in the present, then it does not show a flag.
How can this be decided?
Public function phone number ($ value) {if (preg_match "/ ^ \ (? [0- 9] {3} \)? * -? * [0-9] {3 } * -? * [0-9] {4} $ / ", $ value)) {back true; } return false; } Here is a test case which is currently being shown as a valid phone number, when it should not be:
35353535355535555555
If you are interested in numbers only, then you can filter everything And can check the result:
Public function phone number ($ value) {$ filtered = preg_replace ("/ \ D /", "", $ value); Return Strangel (filtered $) == 10; }
No comments:
Post a Comment