RE: [PHP-WIN] checking for characters
| From: | Ross Fleming | Date: | Wed, 10 Apr 2002 08:00:40 +0000 |
| Subject: | RE: [PHP-WIN] checking for characters | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-12997@lists.php.net to get a copy of this message | ||
what's wrong with ereg and care to give perl related code?...
-----Original Message-----
From: Matt Hillebrand [mailto:matt@medmarket.com]
Sent: 10 April 2002 01:53
To: r.fleming@clara.co.uk; 'Egil Helland'; 'brother'
Cc: php-windows@lists.php.net
Subject: RE: [PHP-WIN] checking for characters
Don't forget about the new .name, and I thought I might mention that
preg()/PCREs would be the way to go if you're trying to make your code
readable.
Matt
-----Original Message-----
From: Ross Fleming [mailto:r.fleming@totalise.co.uk]
For completeness, I thought I'd give the original poster the credit
(just found it): Marko Mihalec <marko.mihalec@ck.tel.hr>
This was posted to the same group ages ago:
if(ereg(
"^[^@
]+@([a-zA-Z0-9\-]+\.)+([a-zA-Z0-9\-]{2}|net|com|gov|mil|org|edu|int)$"
,$email))
{
//email address is valid
}
else
{
// it ain't
}
Or something like that. I'd personally use a couple of explodes though
Ross
-----Original Message-----
From: Matt Hillebrand [mailto:matt@medmarket.com]
Sent: 10 April 2002 00:34
To: 'Egil Helland'; 'brother'
Cc: php-windows@lists.php.net
Subject: RE: [PHP-WIN] checking for characters
I like Egil's idea of readable code using explode and regular
expressions. Or, you could use this function I wrote:
function isValidEmail($email) {
if(strlen($email) < 6)
return false;
$at = -1; // index of '@'
for($i=0; $i<strlen($email); $i++) {
if($email[$i] == '@')
$at = $i;
}
if($at < 1)
return false;
for($i=$at; $i<strlen($email); $i++) {
if($email[$i] == '.')
break;
}
if($i>$at && $i<strlen($email))
return true;
else
return false;
}
Matt
-----Original Message-----
From: Egil Helland [mailto:egil@egil.net]
Brush up on your patternmatching then, brother. Check the php.net manual
on regexp.
If you want more readable code, try splitting the string (explode) on @
first, then split the segment after @ that you now have on . again.
Cheers,
Egil (in Norway, so I am way past bedtime myself :))
On Wednesday, April 10, 2002, at 01:07 AM, brother wrote:
> I tried my best to find a nifty function to check for letters in a
> string but with no luck, maybe the sleepnesfactor has to do with it?
> (it's 01:05am
> here in Sweden).
>
> I have a form that posts some text, one field is a emailadressthing, I
> want to check the string that this field produces and see if there is
> a @ and at
> leaste one . after the @.
>
> help me =)
>
> zzzzz
>
> /brother
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
--
egil helland / it consultant (mcse, web technology)
web: ikon.as / egil.net
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php