Web Design - Web Applications - Internet Marketing
  FAQHome   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile   Private messagesPrivate messages   Log inLog in

Regular Expression for WEB URL and Email

 
Post new topic   Reply to topic    SharkZone Design Forum Index -> CGI, Perl, PHP, and SSI scripting
View previous topic :: View next topic  
Author Message
IT Guy



Joined: 20 Aug 2007
Posts: 1
Location: Las Vegas, Nevada

PostPosted: Tue Nov 06, 2007 9:32 pm    Post subject: Regular Expression for WEB URL and Email Reply with quote

I am writing a form verification in PHP. Does any body know the regular expressioins for a web URL and for an email address.

Thanks
Mike
Back to top
View user's profile Send private message
SharkZoneDesign



Joined: 17 Mar 2007
Posts: 15
Location: Phoenix, Arizona

PostPosted: Tue Nov 06, 2007 9:48 pm    Post subject: Re: Regular Expression for WEB URL and Email Reply with quote

IT Guy wrote:
I am writing a form verification in PHP. Does any body know the regular expressioins for a web URL and for an email address.

Thanks
Mike


Hi Mike,

Below are a few regular expressions that I use. They are not full proof but work OK for form verification. I use these in a module.

Code:

var $regExprs = array (
   'num' => '/^\d+$/',
   'char' => '/^[^\t\n\r]+$/',
   'text' => '/.+/',
   'address' => '/^[\w\#\&\-\'\., ]+$/',
   'username' => '/^[\w\-\.\_ ]+$/',
   'password' => '/^[\w\!\@\#\$\%\^\&\*\-\=\?\:\;\<\>]+$/',
   'zip' => '/(^\d{5}$)|(^\d{5}-\d{4}$)/',
   'phone' => '/^\D*\d{3}?\D*\d{3}?\D*\d{4}?\D*$/',
   'email' => '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/i',
   'website' => '/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}((:[0-9]{1,5})?\/.*)?$/i'
      );


Then the implementation code would look something like below:

Code:

$regex = $this->regExprs[ $type ];
if ( $regex )
{
   if (! preg_match( $regex, $line) )
   {
   $this->error = $this->errorMsgs[ $type ];
   }
}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    SharkZone Design Forum Index -> CGI, Perl, PHP, and SSI scripting All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group