Forum Moderators: coopster

Message Too Old, No Replies

Eregi and domains/emails

Just a few things about eregi!

         

ahmedtheking

1:18 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm still doing my validation script slowly! I'm lost on the whole Eregi thingy!

I visited php.net/eregi but that did not help! It just bombarded me with all this code!

Can someone explain to me how eregi works and what would be suitable experssions for a domain and an email address cos there are so many on the web!

Thanks!

orion_rus

1:38 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



for email i check with such function

function isEmail($emailstring)
{
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$";
if ($emailstring=='') {return true;}
return eregi($regex,$emailstring);
}

i think u understand how it works then)

Hanu

2:01 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$

I wouldn't restrict the part before the @ so much. Also the {1} at the end seems redundant. I suggest:

^[_.+a-z0-9-]+@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,})$

ahmedtheking

3:01 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So what does these mean?

bcolflesh

3:13 pm on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Regulator
[royo.is-a-geek.com...]

Hanu

4:50 pm on Jan 7, 2005 (gmt 0)

10+ Year Member



OK, I'm bored so here is the explanation:

^ matches the beginning of a string

[_.+a-z0-9-]+ matches any at least 1 character long sequence of underscore, period, lower case letters, digits and dash. Square brackets define a set of characters to be matched. A dash that appears between two characters of a character stands for any character between these two characters. If the dash is at the end of a character set, it looses it's special meaning and stands for a just a dash.

@ matches the @ sign

[a-z0-9-]+ matches any at least 1 character long sequence (hence the +) of ... you get it

(\.[a-z0-9-]+)* matches zero or more repitions (hence the *) of a period (period has a special meaning in regular expressions outside of square barackets, so it needs to be escaped by a backslash) followed by any at least 1 character long sequence of ...

\.([a-z]{2,}) matches a period followed by any at least two (hence the {2,}) characters long sequence of lowercase letters

$ matches the end of the string

Note that if you use eregi, the pattern matching is case-insensitive such that [a-z] matches lower case x as well as upper case X.

jshpro2

12:19 am on Jan 9, 2005 (gmt 0)

10+ Year Member



[regexlib.com...]

Free regular expressions for lazy people like me :-)

[edited by: jatar_k at 5:30 pm (utc) on Jan. 9, 2005]
[edit reason] linked it up [/edit]

ahmedtheking

12:14 pm on Jan 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Fantastic! Thank you! I never really understood the syntax/expression until now! :D