Skip to content

Commit

Permalink
Updated documentation and unit tests for phone validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mf committed Apr 29, 2013
1 parent 6e7f3ab commit 10990b7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ Reference
* v::ip()
* v::json()
* v::macAddress()
* v::phone()
* v::sf()
* v::zend()

Expand Down Expand Up @@ -1293,6 +1294,20 @@ Validates a perfect square.
v::perfectSquare()->validate(25); //true (5*5)
v::perfectSquare()->validate(9); //true (3*3)

#### v::phone()

Validates a valid 7, 10, 11 digit phone number (North America, Europe and most
Asian and Middle East countries), supporting country and area codes (in dot,
space or dashed notations) such as:

(555)555-5555
555 555 5555
+5(555)555.5555
33(1)22 22 22 22
+33(1)22 22 22 22
+33(020)7777 7777
03-6106666

#### v::positive()

Validates if a number is higher than zero
Expand Down
2 changes: 1 addition & 1 deletion library/Respect/Validation/Rules/Phone.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class Phone extends AbstractRule
{
public function validate($input)
{
return !empty($input) && preg_match('/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$/', $input);
return !empty($input) && preg_match('/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{1,3})[\)\.\-\s]*(([\d]{3})[\.\-\s]?([\d]{4})|([\d]{2}[\.\-\s]?){4})$/', $input);
}
}

0 comments on commit 10990b7

Please sign in to comment.