Address Match Script

J

JohnW-Mpls

Where can I locate script code to check that duplicate email address
fields on a web form are identical? Too many people are not typing
their email address accurately on application forms on one of the web
sites I maintain. I can easily ask them to repeat the address but
that will be effective only if I have some way of verifying that the
two entries are identical. (I already have code to verify that an
entry is a valid for email addresses.)

I apologize for being lazy (efficient?) and asking for something I can
copy rather than creating my own. I'd like to learn Javascript and
may someday but as I get older, I just want to get jobs done. Talking
to one of my daughters I realized that I have been involved with
computers for over a half century now - sounds impressive, just have
to live long enough! [grin]


-- n
JohnW-Mpls
 
C

Cody Haines

JohnW-Mpls said:
Where can I locate script code to check that duplicate email address
fields on a web form are identical? Too many people are not typing
their email address accurately on application forms on one of the web
sites I maintain. I can easily ask them to repeat the address but
that will be effective only if I have some way of verifying that the
two entries are identical. (I already have code to verify that an
entry is a valid for email addresses.)

I apologize for being lazy (efficient?) and asking for something I can
copy rather than creating my own. I'd like to learn Javascript and
may someday but as I get older, I just want to get jobs done. Talking
to one of my daughters I realized that I have been involved with
computers for over a half century now - sounds impressive, just have
to live long enough! [grin]


-- n
JohnW-Mpls
The following code will do what you want, just replace the values in the
document.getElementById() functions with the ids you have on your two
email fields.

<form onSubmit="return validate_email()" id='email_form'>
<input type="textfield" name="email" id="email" />
<input type="textfield" name="email2" id="email2" />
<input type="submit" />
</form>

<script type="text/javascript">
var validate_email = function() {
email1 = document.getElementById('email').value
email2 = document.getElementById('email2').value
valid = email1===email2
if(!valid)
alert("Emails " + email1 + " and " + email2 + " do not match.");
return valid;
}
</script>
 
G

Garrett Smith

Cody said:
JohnW-Mpls said:
Where can I locate script code to check that duplicate email address
fields on a web form are identical? Too many people are not typing
their email address accurately on application forms on one of the web
sites I maintain. I can easily ask them to repeat the address but
that will be effective only if I have some way of verifying that the
two entries are identical. (I already have code to verify that an
entry is a valid for email addresses.)

I apologize for being lazy (efficient?) and asking for something I can
copy rather than creating my own. I'd like to learn Javascript and
may someday but as I get older, I just want to get jobs done. Talking
to one of my daughters I realized that I have been involved with
computers for over a half century now - sounds impressive, just have
to live long enough! [grin]


-- n
JohnW-Mpls
The following code will do what you want, just replace the values in the
document.getElementById() functions with the ids you have on your two
email fields.

<form onSubmit="return validate_email()" id='email_form'>
<input type="textfield" name="email" id="email" />
<input type="textfield" name="email2" id="email2" />
<input type="submit" />
</form>

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

// (GS) Missing semicolons.
// (GS) creating global properties (don't forget var).
email1 = document.getElementById('email').value
email2 = document.getElementById('email2').value
valid = email1===email2
if(!valid)

// (GS) Not localizing strings.
// (GS) Has side effects.
alert("Emails " + email1 + " and " + email2 + " do not match.");
return valid;
}
</script>
What happens if both fields are empty? That won't solve the OP's
problem; it only adds clutter of an extra form control to the page, plus
extra javascript.

You have a boolean method that is not named as boolean predicate. A
boolean predicate is something that starts with "is" or "has", as in
"isValidEmail".

In the body of that method, you've created three globals.

Next, there is a side effect of an alert with locale-specific string.

If the method is designed to return a boolean value (true for valid,
false otherwise), then what to do with that value (the alert) should be
handled by the caller.

Localizing strings inside of functions is extremely messy.

Instead, if the string is extracted to an object property, that property
can be localized on the server and sent as dynamic content.

// messages.jsp:
var Messages = {
invalidEmail : "<fmt:message key="invalid_email"/>"
};
 
M

Matthias Watermann

[...]
Try (e-mail address removed), (e-mail address removed), (e-mail address removed)
They're all the same e-mail address as far as the SMTP protocol is
concerned.

At the very least, force all test strings to upper (or lower) case.

Beware: only the host/domain part is case-insensitive, while the local
part (i.e. the username) is not. So <[email protected]> and
<[email protected]> are _not_ equal (although they might end up in the
same user's mailbox depending on the destination host's setup), while
<[email protected]> and <[email protected]> may be considered equal
(as far as SMTP is concerned).


--
Matthias
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST M$ ATTACHMENTS
/ \
 
C

Cody Haines

Garrett said:
// (GS) Missing semicolons.
// (GS) creating global properties (don't forget var).
Yeah, my bad, to both of those.
// (GS) Not localizing strings.
// (GS) Has side effects.
What happens if both fields are empty? That won't solve the OP's
problem; it only adds clutter of an extra form control to the page, plus
extra javascript.
If both fields are empty, then the OPs already implemented code should
catch that.
[blah blah blah semantics]
All of that begs the question: Does it really matter?

I get the beef with the side effects: It's bad practice.
The string localization is only an issue when internationalization is
necessary, don't you think? Since the OP didn't specify, I wasn't going
to worry about it.

Regardless: I didn't spend hours writing that. It was written in
thunderbird, in an attempt to be helpful. It seems that's more than
you're willing to do.
 
G

Garrett Smith

Cody said:
[...]

If both fields are empty, then the OPs already implemented code should
catch that.

Did the OP post code that catches that? Ah, no I see he did not. Nor did
he claim to have written such code. Even if the OP had claimed to have
written code, but did not post it, then how would you know it works?
[blah blah blah semantics]

I did not write that.
All of that begs the question: Does it really matter?

Does *what* really matter?
I get the beef with the side effects: It's bad practice.
The string localization is only an issue when internationalization is
necessary, don't you think? Since the OP didn't specify, I wasn't going
to worry about it.

Regardless: I didn't spend hours writing that. It was written in
thunderbird, in an attempt to be helpful. It seems that's more than
you're willing to do.
Code that is presented as being helpful, as yours was, but is actually
the opposite, is harm in disguise.

I encourage you to go and fix the bugs you created. I am not going to do
that for you.
 
C

Cody Haines

Garrett said:
Cody said:
Garrett said:
Cody Haines wrote:
The following code will do what you want, just replace the values in
the document.getElementById() functions with the ids you have on
your two email fields.
[...]

If both fields are empty, then the OPs already implemented code should
catch that.

Did the OP post code that catches that? Ah, no I see he did not. Nor did
he claim to have written such code. Even if the OP had claimed to have
written code, but did not post it, then how would you know it works?
Ah, maybe you should learn to read?
Go back and read the original message again, specifically the part that
says: (I already have code to verify that an entry is a valid for email
addresses.) And, no, I am not assuming that his code is incorrect. I
would assume that he has tested it, and it works, or else he would have
asked a question about it. Unlike you, I don't automatically assume I am
better than everyone around me.
[blah blah blah semantics]

I did not write that. Really? That's all I saw.
All of that begs the question: Does it really matter?

Does *what* really matter?
Nothing you mentioned had any real effect. (minus the points I gave you.
I should have declared the variables. I *should* have had semicolons
(though it doesn't matter).
Code that is presented as being helpful, as yours was, but is actually
the opposite, is harm in disguise.

I encourage you to go and fix the bugs you created. I am not going to do
that for you.
It's seems we define "harmful", and "bugs" differently. In my opinion,
if code functions as I claimed it would, and completes the tasks I
created it to complete consistently, then it is neither 'buggy' or
harmful. I'm curious as to what your definition is.

Although other people have pointed out a (rather major) flaw in the
function, nothing you pointed out detracted in the least from the
operability of the code. (with the exception, again, of not declaring
the variables. My bad).
 
G

Garrett Smith

Cody said:
Garrett said:
Cody said:
Garrett Smith wrote:
Cody Haines wrote:
The following code will do what you want, just replace the values
in the document.getElementById() functions with the ids you have on
your two email fields.
[...]

If both fields are empty, then the OPs already implemented code
should catch that.

Did the OP post code that catches that? Ah, no I see he did not. Nor
did he claim to have written such code. Even if the OP had claimed to
have written code, but did not post it, then how would you know it works?
Ah, maybe you should learn to read?
Go back and read the original message again, specifically the part that
says: (I already have code to verify that an entry is a valid for email
addresses.)

Got it.

And, no, I am not assuming that his code is incorrect. I
would assume that he has tested it, and it works,

Sounds pretty naive. I've read a lot of code. Some of it on this NG.
Including yours. Most of what I see is buggy. Including yours.

or else he would have
asked a question about it. Unlike you, I don't automatically assume I am
better than everyone around me.

You are making assumptions about what I am thinking and turning that
into an ad hominem. Why ? You took it personally that I found bugs in
your code?

In life, you will likely experience much greater failings that you have
demonstrated in your code. The failures will only get worse while you
refuse to except the responsibility for them.

[blah blah blah semantics]

I did not write that.
Really? That's all I saw.

Maybe you should learn to read?
Nothing you mentioned had any real effect. (minus the points I gave you.
I should have declared the variables. I *should* have had semicolons
(though it doesn't matter).

Sounds like you're taking this personally.

You could have fixed the problems and earned a little respect but you
chose to whine instead.
It's seems we define "harmful", and "bugs" differently. In my opinion,
if code functions as I claimed it would, and completes the tasks I
created it to complete consistently, then it is neither 'buggy' or
harmful. I'm curious as to what your definition is.

The method should do one thing.

Your function doesn't separate the "find the invalid part" from "what do
I do after that." It has some side effects.
Although other people have pointed out a (rather major) flaw in the
function, nothing you pointed out detracted in the least from the
operability of the code. (with the exception, again, of not declaring
the variables. My bad).

The worst part of the undeclared identifiers will be in IE, where you're
assigning `email2`. If `email2` is created as a globally-polluted
identifier, then an error will result from "Illegal assignment" in IE.

I did you a favor by pointing it out to you. If you want to continue
with an awful, arrogant attitude, then that is yoru problme.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top