Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: what is this

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy 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
    Regular Coder
    Join Date
    Jun 2002
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    129
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    The Planet Earth Code Poet: True
    Posts
    282
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Provo, UT
    Posts
    142
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a good tutorial somewhere on learning it?

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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; 06-19-2002 at 10:23 PM.
    Alberto http://www.unitedscripters.com/

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Former ASP Forum Moderator - I'm back!

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •