473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Neophyte question

fox
Hi,

Looking through this forum, I cannot help to think that I am way over my
head. Meanwhile, I have a simple purpose and a $15 book on javascript.
Needless to say I need a bit of help. Can someone tell me why this
seems to consider every entered string to be "false" even when it is a
legit email address?

<script language="Javascript" Type="text/javascript">
function FrontPage_Form1_Validator(theForm)
{

if (!(theForm.email.value.indexOf(".")) 3 || !
(theForm.email.value.indexOf("@")) 0);
{
alert("You did not enter a valid email address for the 1 \"email\"
field.");
theForm.email.focus();
return (false);
}

return (true);
}

</script>
Thanks to anyone who might be able to correct my problem,
Fox
Sep 16 '06 #1
8 944
ASM
fox a écrit :
Hi,

Looking through this forum, I cannot help to think that I am way over my
head. Meanwhile, I have a simple purpose and a $15 book on javascript.
Needless to say I need a bit of help. Can someone tell me why this
seems to consider every entered string to be "false" even when it is a
legit email address?
somme errors with your ( ) and more
<script language="Javascript" Type="text/javascript">
function FrontPage_Form1_Validator(theForm)
{

if (!(theForm.email.value.indexOf(".")) 3 || !
if( !( theForm.email.value.indexOf('.') 3)

if not ( point position in email is after 4th place )

And perso, I have an address with point in 2nd position (only a lettre
before) and another address with no point before @
I'lln't be accepted ... :-(
(theForm.email.value.indexOf("@")) 0 );
!( theForm.email.value.indexOf("@") 0 ) // without ';' in end
// because instruction
// continues

rest is OK
Thanks to anyone who might be able to correct my problem,
function FrontPage_Form1_Validator(theForm)
{
if ( !(theForm.email.value.indexOf(".") 3) ||
!(theForm.email.value.indexOf("@") 0) )
{
alert("You did not enter a valid email address for" +
" the \"email\" field.");
theForm.email.focus();
return false;
}
return true;
}
function FrontPage_Form1_Validator(theForm)
{
var mail = theForm.email.value;
if((mail.indexOf(".") < 0) ||
(mail.indexOf("@") < 0) ||
(mail.length < 8))
{
alert("You did not enter a valid email address for" +
" the \"email\" field.");
theForm.email.focus();
return false;
}
return true;
}
Sep 16 '06 #2
fox wrote on 16 sep 2006 in comp.lang.javascript:
Hi,

Looking through this forum, I cannot help to think that I am way over
my head. Meanwhile, I have a simple purpose and a $15 book on
javascript. Needless to say I need a bit of help. Can someone tell me
why this seems to consider every entered string to be "false" even
when it is a legit email address?

<script language="Javascript" Type="text/javascript">
Do not use language="Javascript", [deprecated]
function FrontPage_Form1_Validator(theForm)
Why use Frontpage, it degrades your learning curve IMHO
{

if (!(theForm.email.value.indexOf(".")) 3
If a value is NOT-ed it is bolean and cannot be compared with 3
|| ! (theForm.email.value.indexOf("@")) 0);
same!

And the ; should not be there, as it mankes the "then" of the if clause
an empty statement. [this is your main error, I think!]

if
(
!(theForm.email.value.indexOf(".") 3 )
||
!(theForm.email.value.indexOf("@") 0 )
)

however:

!(theForm.email.value.indexOf(".") 3 )

is the same as:

(theForm.email.value.indexOf('.') <= 3 )

and

!(theForm.email.value.indexOf("@") 0 )

is the same as:

(theForm.email.value.indexOf('@') = 0 )

{
alert("You did not enter a valid email address for the 1 \"email\"
field.");
Use ' and ", simpler:

alert('You did not enter a valid email address for the 1 "email"
field.');

theForm.email.focus();
return (false);
return false;
}

return (true);
return true;
}

</script>
================================

Together:

<script type='text/javascript'>

function My_Form1_Validator(theForm) {
if ((theForm.email.value.indexOf('.') <= 3 ) ||
(theForm.email.value.indexOf('@') = 0 ) ) {
alert('You did ... for the 1 "email" field.');
theForm.email.focus();
return false;
}
return true;
}

</script>

=====================

However, you could use regular expressions for the testing:

<script type='text/javascript'>

function My_Form1_Validator(theForm) {
if (/^.{0,2}\./.test(theForm.email.value) ||
/[^@]/.test(theForm.email.value) ) {
alert('You did ... for the 1 "email" field.');
theForm.email.focus();
return false;
}
return true;
}

</script>
Nothing tested.

The reason for not wanting a period in the first 3 places of an
emailaddress escapes me.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Sep 16 '06 #3
fox wrote:
Looking through this forum, I cannot help to think that I am way over my
head. Meanwhile, I have a simple purpose and a $15 book on javascript.
Needless to say I need a bit of help. Can someone tell me why this
seems to consider every entered string to be "false" even when it is a
legit email address?

<script language="Javascript" Type="text/javascript">
function FrontPage_Form1_Validator(theForm)
{

if (!(theForm.email.value.indexOf(".")) 3
Err. "If the first . character in the email address is not at least the
third character"? So j.*****@example.com isn't an acceptable email address?
|| !
(theForm.email.value.indexOf("@")) 0);
The semi-colon here ends the statement which makes ...
{
alert("You did not enter a valid email address for the 1 \"email\"
field.");
.... et al a simple block (or possibly an anonymous object, I'm a little
unclear on some of the finer points of JS syntax) rather then part of the
if.

--
David Dorward <http://blog.dorward.me.uk/ <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Sep 16 '06 #4
JRS: In article <45**********************@news.orange.fr>, dated Sat, 16
Sep 2006 20:40:20 remote, seen in news:comp.lang.javascript, ASM
<st*********************@wanadoo.fr.invalidposte d :
>function FrontPage_Form1_Validator(theForm)
{
var mail = theForm.email.value;
if((mail.indexOf(".") < 0) ||
(mail.indexOf("@") < 0) ||
(mail.length < 8))
{
alert("You did not enter a valid email address for" +
" the \"email\" field.");
theForm.email.focus();
return false;
}
return true;
}

IMHO, much better tested with a RegExp : see in
<URL:http://www.merlyn.demon.co.uk/js-valid.htm>

AFAICS, the code above will allow '....@@@@' . Consider :-

function FPFV(F) {
var OK = /^.+@.+\...+$/.test(F.email.value)
if (!OK) { alert("bad") ; F.email.focus() }
return OK }

and possible improvements by replacing in the RegExp the "wild" dots
with something more specific - [^@] for initial example

It's a good idea to read the newsgroup and its FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 16 '06 #5
fox <fo*@connexions.netwrote in news:Xns98408C81D50DCfoxconnexionsnet@
65.32.5.121:
Looking through this forum, I cannot help to think that I am way over
my
head. Meanwhile, I have a simple purpose and a $15 book on javascript.
Needless to say I need a bit of help. Can someone tell me why this
seems to consider every entered string to be "false" even when it is a
legit email address?
I can understand your desire to learn Javascript and your present attempt
at writing a useful script. However, I would like to point out that, in
general, it is easier and quicker to find somebody else's code that does
the same thing, and has already been through debugging and is known to
work. (Even if you can find something that *almost* does what you want,
you'll probably save time by editing that script, as opposed to starting
from scratch.) In your case, "validating an email address" has been done
already, dozens of times (maybe hundreds).

Although you won't have that satisfied feeling "I wrote that!" you will
speed up your development process a lot.
Sep 17 '06 #6
Jim Land wrote:
fox wrote:
>Looking through this forum, I cannot help to think that
I am way over my head. Meanwhile, I have a simple purpose
and a $15 book on javascript. Needless to say I need a bit
of help. Can someone tell me why this seems to consider
every entered string to be "false" even when it is a
legit email address?

I can understand your desire to learn Javascript and your
present attempt at writing a useful script. However, I
would like to point out that, in general, it is easier and
quicker to find somebody else's code that does the same
thing, and has already been through debugging and is known
to work. (Even if you can find something that *almost* does
what you want, you'll probably save time by editing that
script, as opposed to starting from scratch.) In your case,
"validating an email address" has been done already, dozens
of times (maybe hundreds).

Although you won't have that satisfied feeling "I wrote that!"
you will speed up your development process a lot.
Would that speed up development work? In principle nobody should be
employed to write javascript without having learnt it first so time
spent learning it would not be development work. In practice employers
may as people without javascript skills to write javascript, but then
they must expect them to be learning as they go along, and so expecting
relatively slow development. And ultimately anyone employed to write
javascript is going to be asked to do something that they cannot find an
example of (possibly because it is not possible), at which point they
will have no choice but learn to write it for themselves. For any
individual the time needed to learn javascript will not be significantly
different whenever they do it, but if they have been producing
javascript for some time the expectations of there employer may be such
that stopping to learn the subject for real, mid project, is
inconvenient to say the least.

Also, development time is only part of the picture. With at least 90% of
published javascript being atrociously poor a strategy of adapting it an
using it is likely to produce more poor code, with all the usual
implications for ongoing maintenance (and consequential associated
expense). Saving development time at a disproportional cost in
maintenance is doing nobody any favours.

Richard.
Sep 17 '06 #7

fox wrote:
Hi,

Looking through this forum, I cannot help to think that I am way over my
head. Meanwhile, I have a simple purpose and a $15 book on javascript.
Needless to say I need a bit of help. Can someone tell me why this
seems to consider every entered string to be "false" even when it is a
legit email address?

<script language="Javascript" Type="text/javascript">
function FrontPage_Form1_Validator(theForm)
{

if (!(theForm.email.value.indexOf(".")) 3 || !
(theForm.email.value.indexOf("@")) 0);
{
alert("You did not enter a valid email address for the 1 \"email\"
field.");
theForm.email.focus();
return (false);
}

return (true);
}

</script>
Thanks to anyone who might be able to correct my problem,
Fox
Is there any particular reason you don't want to use a Regular
Expression?

Surely it would be less code and time to use one?

Sep 17 '06 #8
JRS: In article <Xn**********************************@216.168.3.44 >,
dated Sun, 17 Sep 2006 03:20:26 remote, seen in
news:comp.lang.javascript, Jim Land <Rr**********@hotmail.composted :
>
I can understand your desire to learn Javascript and your present attempt
at writing a useful script. However, I would like to point out that, in
general, it is easier and quicker to find somebody else's code that does
the same thing, and has already been through debugging and is known to
work.
With Internet Search Engines, it is even more easy and quick to find
someone else's code that attempts the same thing and does it badly. The
immediate project may be "completed" faster, but may by false rejections
lose customers or by false acceptances waste company resources.

E-address validation code, for example, that does not allow . before @
or restricts the TLD to 2/3 characters. Or code which is, for its
length and complexity, unnecessarily liberal, allowing for example more
than one @ .

Only for those with a certain amount of skill and pessimism is an
unguided search likely to be efficient - using a well-maintained FAQ is
good, for example, but using a Web site with an ill-edited collection of
old answers is not.

It's a good idea to read the newsgroup and its FAQ.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Sep 18 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
1
by: Randy Powell | last post by:
HI folks, I'm a neophyte Access administrator and user. I've got a database working pretty well that I received a lot of help on here. Thanks! I supervise a small children's crisis program and...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
9
by: James | last post by:
Complete neophyte to VC++. I do have a base knowledge of how API calls work and the general structure of these applications, but I'm getting bogged down with details. Just a few, relatively...
0
by: UncleRic | last post by:
Environment: Mac OS X (10.4.10) on MacBook Pro I'm a Perl Neophyte. I've downloaded the XML::Parser module and am attempting to install it in my working directory (referenced via PERL5LIB env): ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.