Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Edit</strong></p> <p>Your company is asking you to do the address validation on the server. Sometimes you want to do it in both places, ie:</p> <ul> <li>On the client: To provide instant feedback about whether input is valid <em>before</em> submitting</li> <li>On the server: To validate the input in case some bad input got through</li> </ul> <p>Your form data is submitted to the server via a <code>POST</code> request (usually), so the PHP endpoint that handles the request must get the form field from the request and validate it.</p> <p>For instance, you might "get" the email address by doing:</p> <p><code>$emailAddress = $_POST["email"];</code></p> <p>The <code>$_POST</code> array is specific to each request and has all of the form data in a dictionary (well really an array I think, but whatever). In general, you can get the form data by doing <code>$_POST["the_input_id"]</code> where <code>the_input_id</code> is the form element's input ID.</p> <p>Once you get the stuff you need, then you can do the validation.</p> <p><strong>PHP Side</strong></p> <p>See <a href="https://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address">Using a regular expression to validate an email address</a> to find a good RegEx to validate your email addresses.</p> <p>There is no "canonical" RegEx that I know of for email addresses as different servers allow different sorts of addresses. The RFC for what actually is a valid email address is not uniformly followed.</p> <p>For instance, a very intense RegEx is available at <a href="http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html" rel="nofollow noreferrer">http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html</a>.</p> <p>Then use php's built-in RegEx functions, ie:</p> <pre><code>$EmailRegEx = "^[a-zA-Z0-9.!#$%&amp;'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$"; $InputAddress = "tacos_tacos_tacos@nowhere.com"; $EmailAddressValid = preg_match($EmailRegEx, $InputAddress); if ($EmailAddressValid) { $this-&gt;_SendMe(); } </code></pre> <p>See <a href="http://www.developphp.com/view_lesson.php?v=224" rel="nofollow noreferrer">http://www.developphp.com/view_lesson.php?v=224</a> for a simple example.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload