Web Analytics Made Easy -
StatCounter what is this - CodingForum

Announcement

Collapse
No announcement yet.

what is this

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • what is this

    please explain to me this code ,idont under stand it specially
    function check email()



    <form name="validation" onSubmit="return checkbae()">
    Please input a valid email address:<br>
    <input type="text" size=18 name="emailcheck">
    <input type="submit" value="Submit">
    </form>
    <script language="JavaScript1.2">

    //Advanced Email Check credit-
    //By JavaScript Kit (www.javascriptkit.com)
    //Over 200+ free scripts here!

    var invalidaddress=new Array()
    invalidaddress[0]="hotmail"
    invalidaddress[1]="rocketmail"
    invalidaddress[2]="yahoo"
    invalidaddress[3]="zdnetmail"
    //extend or shorten this list if neccessary

    var testresults
    function checkemail(){
    var invalidcheck=0;
    var str=document.validation.emailcheck.value
    var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(str)){
    var tempstring=str.split("@")
    tempstring=tempstring[1].split(".")
    for (i=0;i<invalidaddress.length;i++){
    if (tempstring[0]==invalidaddress[i])
    invalidcheck=1
    }
    if (invalidcheck!=1)
    testresults=true
    else{
    alert("Please input a more official email address!")
    testresults=false
    }
    }
    else{
    alert("Please input a valid email address!")
    testresults=false
    }
    return (testresults)
    }
    </script>

    <script>
    function checkbae(){
    if (document.layers||document.getElementById||document.all)
    return checkemail()
    else
    return true
    }
    </script>

    <p align="center"><font face="arial" size="-2">This free script provided by</font><br>
    <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
    Kit</a></font></p>

  • #2
    hi,

    Description: A script that closely examines the content of a form box to ensure that the user entered a valid email address. If not, the form submition is canceled, and the surfer prompted to re-enter a valid address. The script makes the following assumptions regarding what a valid email address is:

    -Contains a least one character preceding the "@"
    -Contains a "@" following the preceding character(s)
    -Contains at least one character following the "@", followed by a dot (.), followed by either a two character or three character string (a two character country code or the standard three character US code, such as com, edu etc)

    Note that this script requires NS 4+ or IE 4+ to function- all other browsers will simply not participate in the form validation process.

    Comment


    • #3
      ok iknow that but idon't understand the following code
      it's strang for me
      what the purpose of (split,test,using array,strange string in var filter)
      -----------------------------------------------------------------------

      var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
      if (filter.test(str)){
      var tempstring=str.split("@")
      tempstring=tempstring[1].split(".")
      for (i=0;i<invalidaddress.length;i++){
      if (tempstring[0]==invalidaddress[i])
      invalidcheck=1

      Comment


      • #4
        filter is a variable that uses regular expressions to put these rules:

        -Contains a least one character preceding the "@"
        -Contains a "@" following the preceding character(s)
        -Contains at least one character following the "@", followed by a dot (.), followed by either a two character or three character string (a two character country code or the standard three character US code, such as com, edu etc)
        into one line of code. Regular expressions are very helpful but as you see can get a bit complex.

        test() checks to see if something matches the rules set up in the regular expression. Here is a simple example:

        <script type="text/javascript">
        str="567"
        filter=/^\d+$/
        alert(filter.test(str))
        </script>


        The string "str" is just a bunch of numbers in this case. The filter is a regular expresion that says:

        ^ (start at the beginning)
        \d+ (there can only be one or more numbers
        $ (end at the end of the string)

        Try adding a leter to str to see what happens. I am not as strong in regular expressions as I would like to be but I strongly suggest pciking it up.

        Comment


        • #5
          Is there a good tutorial somewhere on learning it?
          I try to convince 'em that I am computer geek, but I just can't do it. Why? Oh why?

          Comment


          • #6
            just check for, say, "javascript regular expressions" on search engines. Originally, reg expressions were a Perl thing.
            Probably their worst feature is the so called greed. Once you stumble across greed after you've learned them (they're not really difficult, just odd at sight), a file that may help you understand greed at least the way I understood it is on my site (spellbinders section, "Understanding Greed in Regular Expressions", with also a small form where you can test your own regular expression skills)

            In JavaScript we have several methods that work with regular expreession: match, test, exec... you may want a manual. Goodman' JS Bible is the best in my opinion, also Flanagan's good.
            Last edited by TrueLies; Jun 19, 2002, 05:23 PM.
            Alberto http://www.unitedscripters.com/

            Comment


            • #7




              A world community for web developers, evolt.org promotes the mutual free exchange of ideas, skills and experiences.


              ASP: http://www.4guysfromrolla.com/webtec...ressions.shtml
              Former ASP Forum Moderator - I'm back!

              If you can teach yourself how to learn, you can learn anything. ;)

              Comment

              Working...
              X