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 8 of 8
  1. #1
    kas
    kas is offline
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with simple javascripting (coursework)

    This is supposed to be a script to validate a email address in a textbox. Can anyone help me edit this with the following:
    • correct indentation
    • meaningful identifiers (variable, function and control names)
    • correct use of Hungarian notation for variable identifiers the textbox identifier
    • suitable comments
    • appropriate spacing


    <script language = "javascript">

    function a()
    {
    var v1 = B.value;
    var n1;
    var n2 = 0;

    for (n1= 0; n1 < v1.length; n1++)
    {
    if (v1.charAt(n1) == "@" )
    {
    n2++;
    }
    }

    if ((n2 != 1) || v1.charAt(0) != "")
    {
    alert( "Your e-mail address is incorrect”);
    }
    }

    </script>
    Last edited by kas; 05-22-2008 at 12:06 PM.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Why not use This email validator

  • #3
    kas
    kas is offline
    New to the CF scene
    Join Date
    May 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have to correct the one given.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    See forum rules re homework. It is not in your interests in the long run if other people do your homework for you. This is a very, very simple assignment and if you have paid attention in class you ought to be able to do it easily.

    Hint - simply count the @ signs and if result is zero or more than one then the email address is not valid.


    111,111,111 x 111,111,111 = 12,345,678,987,654,321
    Last edited by Philip M; 05-22-2008 at 12:39 PM.

  • #5
    New Coder
    Join Date
    Apr 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I am also having the same issue and if it was as simple as paying attention in lectures we wouldn't be here asking for help. The content has been rushed through so quickly only a few with prior coding experience can resolve these queries without support.

    Some assistance would really be of great help.

    The best I have got to is this:

    <script type="text/javascript">
    function checkEmail()
    {

    var strEmail = txtB.value;
    var intCount;
    var intInput = 0;

    for (intCount= 0; intInput < strEmail.length; intCount++)
    {
    if (strEmail.charAt(intCount) == "@" )
    {
    intInput++;
    }
    }
    if ((intInput != 1) || strEmail.charAt(intCount - 1) != "7")
    {
    alert( "Your e-mail address is incorrect”);
    }
    }
    </script>
    <body>
    <P align="left"><input name="cmdCheckEmail" id="cmdCheckEmail" onclick="checkEmail() "type="submit" value="Check email"/>
    <P align="left"><strong>Type your email address here:</strong><input name="txtB" type="text" id="txtB" />
    </body>
    </html>

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Once again: we don't do the other people's homework. Don't mention that you have dug a 2 years old thread.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Look very carefully at
    alert( "Your e-mail address is incorrect”);
    and you will find a syntax error.

    for (intCount= 0; intInput < strEmail.length; intCount++)
    See anything wrong here?

    Rather than your loop you could use the indexOf() and lastIndexOf() methods.

  • #8
    New Coder
    Join Date
    Apr 2011
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks for the hints, I'll take another look through.


  •  

    Posting Permissions

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