| View previous topic :: View next topic |
| Author |
Message |
IT Guy
Joined: 20 Aug 2007 Posts: 1 Location: Las Vegas, Nevada
|
Posted: Tue Nov 06, 2007 9:32 pm Post subject: Regular Expression for WEB URL and Email |
|
|
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 |
|
 |
SharkZoneDesign
Joined: 17 Mar 2007 Posts: 15 Location: Phoenix, Arizona
|
Posted: Tue Nov 06, 2007 9:48 pm Post subject: Re: Regular Expression for WEB URL and Email |
|
|
| 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 |
|
 |
|
|
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
|