Looking for a JavaEE Architect or Potential Tech Co-Founder?
Please don't hesitate to contact me.

PHP US phone, zip regular expression validator

I want a format:

a.) phone: (xxx)-(xxx)-(xxxx)
b.) zip: (xxxxx)-(xxxx); -(xxxx) is optional

But, I couldn't find them so I created mine anyway.


$us_phone = "^(\()[0-9]{3}(\))(\-)(\()[0-9]{3}(\))(\-)(\()[0-9]{4}(\))$";
$us_zip = "^((\()[0-9]{5}(\)))(-(\()[0-9]{4}(\)))?$";

$code = $us_phone;

function validate($code, $value) {
if(ereg($validator, $value)) {
return true;
else
return false;
}
PHP US phone, zip regular expression validator PHP US phone, zip regular expression validator Reviewed by czetsuya on Sunday, June 28, 2009 Rating: 5

No comments:

Powered by Blogger.