Answered Questions

  • How to use email validation in Java script.Like User can't enter invalid email address?

    Star Read Best Answer

    Editorial / Best Answer

    bicu  

    • Member Since Sep-2005 | Feb 2nd, 2006


    First of all, here is the javascript function that tests if an email address is valid.
    It checks for a lot of things: to see if the email contains a "@" sign and a dot, checks to see if the @ is before the dot, and so on.

    <script>
    function isMail(str)
    {
       var at="@";
       var dot=".";
       var lat=str.indexOf(at);
       var lstr=str.length;
       var ldot=str.indexOf(dot);
       if (str.indexOf(at)==-1) return false;
       if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
       if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
       if (str.indexOf(at,(lat+1))!=-1) return false; if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
       if (str.indexOf(dot,(lat+2))==-1) return false;
       if (str.indexOf(" ")!=-1) return false;
       return true;
    }

    // the next function will be used to validate the form. I made this as a separate function because you might want to validate more fields.
    function validate_form()
    {
       if (!isMail(document.form1.mail.value))
       {
          alert("Please enter a valid email address");
          document.form1.mail.focus();
          return false;
       }
       // if the value entered is not a valid email address, 
       // we show a message, focus on the field and return false.
       // returning false will make sure the form is not submitted

       // if we got here, it means the email address is valid
       return true;
       // return true means that the form is submitted.
    }

    </script>

    After placing this function in the code, here is what you need to put in the form.

    Let's say the form only has the email address and a submit button.

    <form action="/" method="post" onsubmit="return validate_form()" name="form1">
    <input type="text" name="email" value="">
    <input type="submit" name="submit_button" value="continue">
    </form>

  • Which one is faster DELETE/TRUNCATE? Why?

    Harishankar Sahu

    • Nov 24th, 2017

    Truncate is faster. Because, its a DDL. So, no rollback information is stored. Truncate also does not consider integrity constraints; while delete does.

    shaik

    • Sep 7th, 2016

    DELETE is a Safe mode of operation as it can be ROLLBACKed whereas TRUNCATE is Faster operation but cannot be ROLLBACKed.
    DELETE can be Few Records based on WHERE Clause while the TRUNCATE is a Full operation.