Page 1 of 1

how do i check url in correct format

Posted: Tue Nov 24, 2009 6:37 am
by chris_s_22
this is what im using to check if a email in correct format
can anyone tell me if this would reject any email address

Code: Select all

if(!preg_match('/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/', $_POST[email]))  
also how would i check a url in correct format

Re: how do i check url in correct format

Posted: Tue Nov 24, 2009 11:41 am
by AbraCadaver
Try filter_var(). Use FILTER_VALIDATE_EMAIL or FILTER_VALIDATE_URL. No reason to reinvent the wheel.

-Shawn