ereg statements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cerebral Believer

    ereg statements

    Is this a good ereg statement?

    if
    (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,}){1}$",$ema il_1
    or $email_2))
    {
    unset($_GET['do']);
    $message_new = "<font color='#cc0000' >$email_1 or $email_2 is not a
    valid email address.
    Please try again.</font>";
    include("login_ form.php");
    exit();

    I am just trying to check if the e-mail fields _1 & _2 on the form contain
    valid characters, without getting to complicated. The form I am using it in
    keeps returning that I am not entering a valid e-mail address, such
    "chris.bolton@n tlworld.com", or "chris@myweb.co .uk",or "chris@ntlworld .com"
    not sure why this is the case?

    Regards,
    C.B.


  • Janwillem Borleffs

    #2
    Re: ereg statements

    Cerebral Believer wrote:
    Is this a good ereg statement?
    >
    The regular expression on itself is fine, but the error is the '$email_1 or
    $email_2' condition, which evaluates to '1' or '' before it's compared. You
    need to apply the regular expression for each email address seperately.

    Also, it's recommended to use the PCRE library instead of the POSIX-based
    ereg* functions. See http://www.php.net/pcre for more information.


    JW


    Comment

    • Koncept

      #3
      Re: ereg statements

      In article <kdqTg.75730$DB 3.17407@newsfe6-gui.ntli.net>, Cerebral
      Believer <nospamthanks@h adenoughalready .comwrote:
      Is this a good ereg statement?
      >
      if
      >
      (!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]{1,})*\.([a-z]{2,})
      {1}$",$email_1
      or $email_2))
      {
      unset($_GET['do']);
      $message_new = "<font color='#cc0000' >$email_1 or $email_2 is not a
      valid email address.
      Please try again.</font>";
      include("login_ form.php");
      exit();
      >
      I am just trying to check if the e-mail fields _1 & _2 on the form contain
      valid characters, without getting to complicated. The form I am using it in
      keeps returning that I am not entering a valid e-mail address, such
      "chris.bolton@n tlworld.com", or "chris@myweb.co .uk",or "chris@ntlworld .com"
      not sure why this is the case?
      >
      Regards,
      C.B.
      >
      >

      Try this:

      <?php
      function is_valid_email( $email='') {
      return (bool) preg_match( "/^
      [\d\w\/+!=#|$?%{^&}*`' ~-]
      [\d\w\/\.+!=#|$?%{^&}* `'~-]*@
      [A-Z0-9]
      [A-Z0-9.-]{1,61}
      [A-Z0-9]\.
      [A-Z]{2,6}$/ix", $email);
      }
      ?>

      --
      Koncept <<
      "The snake that cannot shed its skin perishes. So do the spirits who are
      prevented from changing their opinions; they cease to be a spirit." -Nietzsche

      Comment

      • John Dunlop

        #4
        Re: ereg statements

        Koncept:
        [Cerebral Believer:]
        >
        Is this a good ereg statement?
        No. The pattern tries to weed out malformed e-mail addresses but fails
        because it is too restrictive. A regular expression to match all
        well-formed e-mail addresses would be complex, since in addition to the
        productions you would need to include from RFC2822, the pattern would
        involve recursion of a subpattern if it was to allow comments.
        Try this:
        A prime bogosity indicator on Usenet.

        --
        Jock

        Comment

        • Jerry Stuckle

          #5
          Re: ereg statements

          John Dunlop wrote:
          Koncept:
          >
          >
          >>[Cerebral Believer:]
          >>
          >>
          >>>Is this a good ereg statement?
          >
          >
          No. The pattern tries to weed out malformed e-mail addresses but fails
          because it is too restrictive. A regular expression to match all
          well-formed e-mail addresses would be complex, since in addition to the
          productions you would need to include from RFC2822, the pattern would
          involve recursion of a subpattern if it was to allow comments.
          >
          >
          >>Try this:
          >
          >
          A prime bogosity indicator on Usenet.
          >
          I did see a regex which would handle all possible addresses. Don't
          remember where I saw it off hand, but it was around 6500 chars long.

          Obviously it's not easy to validate email addresses!

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • John Dunlop

            #6
            Re: ereg statements

            Jerry Stuckle:
            I did see a regex which would handle all possible addresses. Don't
            remember where I saw it off hand, but it was around 6500 chars long.
            To give a rough idea to anyone who thinks it's easy, Jerry, point your
            browser here:



            That regular expression purportedly validates the well-formedness of
            RFC822 e-mail addresses excluding comments. In other words even that
            monster couldn't validate e-mail addresses itself. Since RFC2822
            obsoleted RFC822, the pattern would need to be even larger, because
            RFC2822 allows obsolete productions from RFC822 as well as its own.
            Obviously it's not easy to validate email addresses!
            Not half.

            (Slightly pedantic, but validating e-mail addresses and validating
            e-mail address syntax are two different things. Validating e-mail
            addresses entails dicovering if the e-mail address is in use;
            validating e-mail address syntax entails checking that the syntax
            matches that allowed by RFC2822. Go on, witty retort: 'you're not
            being pedantic; you're being pernickety'.)

            Enjoy the weekend!

            --
            Jock

            Comment

            • Jerry Stuckle

              #7
              Re: ereg statements

              John Dunlop wrote:
              Jerry Stuckle:
              >
              >
              >>I did see a regex which would handle all possible addresses. Don't
              >>remember where I saw it off hand, but it was around 6500 chars long.
              >
              >
              To give a rough idea to anyone who thinks it's easy, Jerry, point your
              browser here:
              >

              >
              That regular expression purportedly validates the well-formedness of
              RFC822 e-mail addresses excluding comments. In other words even that
              monster couldn't validate e-mail addresses itself. Since RFC2822
              obsoleted RFC822, the pattern would need to be even larger, because
              RFC2822 allows obsolete productions from RFC822 as well as its own.
              >
              >
              >>Obviously it's not easy to validate email addresses!
              >
              >
              Not half.
              >
              (Slightly pedantic, but validating e-mail addresses and validating
              e-mail address syntax are two different things. Validating e-mail
              addresses entails dicovering if the e-mail address is in use;
              validating e-mail address syntax entails checking that the syntax
              matches that allowed by RFC2822. Go on, witty retort: 'you're not
              being pedantic; you're being pernickety'.)
              >
              Enjoy the weekend!
              >
              You've got it! :-)

              And BTW - you right about the difference. And you can't validate an
              email address. Nowadays too many ISP's bit-bucket mail to invalid
              addresses rather than return a message. Too many spammers were using
              the lack of a response to indicate they hit a valid email address.

              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstucklex@attgl obal.net
              =============== ===

              Comment

              Working...