1. I've started a massive SPAM purge, any accounts that have spammed are being removed, also for a short period new user signups are disallowed until the SPAM cleaning is finished.

How to Validate an email address in a form.

Discussion in 'PHP' started by jamesprx, Dec 15, 2008.

  1. jamesprx

    jamesprx New Member

    Joined:
    Dec 15, 2008
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Hii Guys. .
    i want to know that how we validate an email address which user enters in a field in a form.Please Give me the code.
    Jimmy Scott
    Loading...
  2. hanna_depp

    hanna_depp New Member

    Joined:
    Aug 24, 2010
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    0
    Usually, the information you submit is checked on the server side and you will be asked to fix possible errors, if any. This procedure is called form validation.
  3. Ark21

    Ark21 New Member

    Joined:
    Jun 10, 2011
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Search google for regex email validation and you will probably find some good solution.
  4. shrivcom

    shrivcom New Member

    Joined:
    Nov 15, 2011
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    1
    For email validation
    ->It is done under the script tag in "javascript"
    -> you can divide the email validation in two parts
    ->first validate for empty text field
    -> validate using regular expressions in PHP for the symbols used in email id format and a valid domain name.
  5. Jill Smith

    Jill Smith Member

    Joined:
    Mar 20, 2012
    Messages:
    109
    Likes Received:
    11
    Trophy Points:
    18
    Gender:
    Female
    Location:
    United Kingdom
    There are two ways to validate email viz 1>Using javascript (client side)2>Using any server side language

    In javascript
    function validate(form_id,email) {

    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.forms[form_id].elements[email].value;
    if(reg.test(address) == false) {

    alert('Invalid Email Address');
    return false;
    }
    }


    .
  6. davidsmith

    davidsmith Member

    Joined:
    Jun 21, 2013
    Messages:
    28
    Likes Received:
    1
    Trophy Points:
    6
    write function in javascript and call that function on form submit event.
  7. Luca tall

    Luca tall New Member

    Joined:
    Nov 6, 2013
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Male
    Location:
    India
    Here is the coding for form email validation.

    $error[]=array(); //
    if(empty($_POST['emailid'])) // for checking emaild id is empty or not
    {
    $error[]="enter your email id";
    }
    else{
    if (preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/",
    $_POST['emailid'])) // For validating email format
    {
    $emailid=$_POST['emailid'];
    }
    else
    {
    $error[]= "invalid emailid";
    }}
  8. Maureen P. James

    Maureen P. James Member

    Joined:
    Jul 8, 2014
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Male
    Location:
    UK, london
    Which platform you have used to create form here is simple HTML is coded for validating an email.
    <!DOCTYPE html>
    <html lang="en">

    <head>
    <title>&lt;input type=&quot;email&quot;&gt;</title>
    </head>

    <body>

    <fo
    rm>

    <input type="email" placeholder="m
    e">

    <input type="submit">
    </form>

    </body>

    </html>
  9. alexjames212

    alexjames212 Member

    Joined:
    Jun 18, 2014
    Messages:
    55
    Likes Received:
    4
    Trophy Points:
    8
    Gender:
    Male
    Location:
    India, Kerala
  10. Richen ji

    Richen ji Member

    Joined:
    Sep 15, 2014
    Messages:
    15
    Likes Received:
    40
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Leh ladakh
    Hi;
    to validate an email address,here is example--

    $email = test_input($_POST["email"]);
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
    $emailErr = "Invalid email format";
    }
  11. Bedi

    Bedi Member

    Joined:
    Sep 16, 2014
    Messages:
    15
    Likes Received:
    32
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,
    we will learn about what is oveloading.

    example:

    <?php


    class desireprompt{

    function __call($method,$arguments){
    if($method=="set_name"){

    if(count($arguments)==1){
    echo "The name of your friend : ",$arguments[0],"<br>";
    }



    if(count($arguments)==2){
    echo "The name of your two friends : ",$arguments[0]," and ",$arguments[1];
    }
    }
    }
    }

    $obj=new desireprompt;
    $obj->set_name("Ram");
    $obj->set_name("ram","sita");

    ?>


    output:

    The name of your friend : Ram
    The name of your two friends : ram and sita
  12. Bedi

    Bedi Member

    Joined:
    Sep 16, 2014
    Messages:
    15
    Likes Received:
    32
    Trophy Points:
    13
    Gender:
    Male
    Location:
    Gurgaon
    Hi,

    what is autoloading.

    example:

    *****mainprogram of 'autoloading.php' file----


    <?php
    function __autoload($class){

    include $class.'.php';

    }

    $obj=new desireprompt1;
    $obj->show();
    $obj->show1();

    ?>




    ****desireprompt1.php file------

    <?php

    class desireprompt1 extends desireprompt{


    function show1(){
    echo "I am from desireprompt1";

    }

    }

    ?>



    ****desireprompt.php file----

    <?
    class desireprompt{

    function show(){
    echo "I am from desirepromt,<br>";

    }

    }

    ?>



    output:

    I am from desirepromt,
    I am from desireprompt1

Share This Page