Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

URL and Email Validation

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

URL and Email Validation

Postby Joel » Mon Jul 28, 2003 8:17 pm

Hi, I'm looking for a URL validation.

Also, I have this email validator.

Code: Select all
ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'.'@'.
      '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $value)


But it I've noticed it lets through emails with $ and # and ! etc.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby swirlee » Mon Jul 28, 2003 8:37 pm

A site I've found recently and accepted as my personal lord and saviour is RegExLib.com, the Regular Expression Library. It should solve all of your regex needs and then some. Be sure to read the comments on the pages, as sometimes they give improved versions, fixes, etc.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Mon Jul 28, 2003 9:02 pm

Once again, Swirlee to the rescue. I found a better code for the email one now but I must look about this site.
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby reinheitphp » Mon Jul 28, 2003 10:14 pm

Here is another email varification...

if(ereg("^(.+)@(.+)\\.(.+)$",$email))
{
}else{
echo("<script>alert(\"You must supply a vaild email\");history.go(-1)</script>");
exit;
}

for Url you could try...
(if havent tried it but im just guessing; experimenting)

if(ereg("http://www.(.+)\\.(.+)$",$url))
{
}else{
echo("<script>alert(\"You must supply a vaild URL\");history.go(-1)</script>");
exit;
}
reinheitphp
New php-forum User
New php-forum User
 
Posts: 12
Joined: Sun Jul 13, 2003 10:58 pm

Postby swirlee » Tue Jul 29, 2003 5:45 am

I'm no regex expert, but it looks like your e-mail will match anything before the @ and anything with a dot in it after the @. Likewise, your URL expression seems to match any URL that starts with www. and has a dot somewhere after. So a literal !!!!!@!!!!!.!!!!! would seem to be a valid e-mail and http://www.!!!!!.!!!!! a valid URL, but not http://swirlee.org/. Hmm.
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby Joel » Tue Jul 29, 2003 3:59 pm

These are the patterns I am using, which work quite nicely.

Code: Select all
$emailpattern = '^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$';

$urlpattern = '^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$';

Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.