Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-22-2008, 11:48 AM   PM User | #1
kas
New to the CF scene

 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kas is an unknown quantity at this point
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..
kas is offline   Reply With Quote
Old 05-22-2008, 12:09 PM   PM User | #2
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
Why not use This email validator
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 05-22-2008, 12:21 PM   PM User | #3
kas
New to the CF scene

 
Join Date: May 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
kas is an unknown quantity at this point
I have to correct the one given.
kas is offline   Reply With Quote
Old 05-22-2008, 12:35 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is online now   Reply With Quote
Old 04-05-2011, 03:23 PM   PM User | #5
huskie
New Coder

 
Join Date: Apr 2011
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
huskie is an unknown quantity at this point
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>
huskie is offline   Reply With Quote
Old 04-05-2011, 03:28 PM   PM User | #6
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
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
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 04-05-2011, 03:54 PM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is online now   Reply With Quote
Old 04-05-2011, 10:40 PM   PM User | #8
huskie
New Coder

 
Join Date: Apr 2011
Posts: 33
Thanks: 2
Thanked 0 Times in 0 Posts
huskie is an unknown quantity at this point
Thanks for the hints, I'll take another look through.
huskie is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:34 PM.


Advertisement
Log in to turn off these ads.