Jump to content


Photo

Test for email address in string


  • Please log in to reply
4 replies to this topic

#1 carole2

carole2
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 July 2006 - 04:06 PM

I would like a reg expression that can check for the existence of an email address in a string. This is to prevent users from entering an email address into a particular field.

regards
carole

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 04:20 PM

Prehaps this thread might be able to help you out. Look at post number 3 by toplay.

#3 carole2

carole2
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 July 2006 - 06:27 PM

Prehaps this thread might be able to help you out. Look at post number 3 by toplay.


Thanks that was helpful but i would like a reg expression that would allow all text except for an email address, if that is possible.

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 26 July 2006 - 07:07 PM

You do something like this:
<?php

$text = "Hey my email adddy is abc123@abc.def isnt it nice";

if(preg_match("/([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})/i", $text))
{
    echo "Email adddy detected, We do not accept email addresses within strings!";
}
else
{
    echo "No email addy dectected";
}

?>


#5 carole2

carole2
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 26 July 2006 - 07:53 PM

You do something like this:

<?php

$text = "Hey my email adddy is abc123@abc.def isnt it nice";

if(preg_match("/([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})/i", $text))
{
    echo "Email adddy detected, We do not accept email addresses within strings!";
}
else
{
    echo "No email addy dectected";
}

?>


Thanks..
Yeah thats a possibility i thought of  that already. .. I am using a form class that validates on the server side and the client side. On the client side javascript is created from the reg expression. So i was looking for just a reg expression that would not accept any text that contained an email address. Its not that important as i could validate it on the server side only with the above code. 

Thanks for your input...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users