/    Sign up×
Community /Pin to ProfileBookmark

validating an email address with 2 form fields

i have 2 form fields, one is primary email, the other is confirm email. how can i validate the confirm email so that it is the same as the primary email?
what javascript code could i use for that?
thanks

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — [code=html]
<script type="text/javascript">
function validate(){
if(arguments[0].email1.value==arguments[0].email2.value)
return true
alert("Your email address don't match the confirmation aemail address!")
return false
}
</script>

<form action="javascript:void(alert('submit form'))" onsubmit="return validate(this)">
<input type="text" name="email1" value=""><br>
<input type="text" name="email2" value=""><br>
<input type="submit">
</form>
[/code]


There ya go, how simple is that! ?
Copy linkTweet thisAlerts:
@mikewootenauthorMay 12.2005 — ok, how can you check to see if the email address are the same in both fields and how do you check for the '@' sign?

thanks
Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — Sounds like you should sign my guestbook now! ? (see sig.)
[code=html]
<script type="text/javascript">
function validate(){
if(arguments[0].email1.value!=arguments[0].email2.value)
{alert("Your email address don't match the confirmation email address!");return false}

if(arguments[0].email1.value.indexOf("@")==-1)
{alert("Please enter your email address in this format:[email protected]");return false}

if(arguments[0].email1.value.length<4)
{alert("Your email address is too short to be real!");return false}

return true
}
</script>

<form action="javascript:void(alert('submit form'))" onsubmit="return validate(this)">
<input type="text" name="email1" value=""><br>
<input type="text" name="email2" value=""><br>
<input type="submit">
</form>
[/code]


As an added bonus I made it accept only email addresses with a length of 4 or more characters.
Copy linkTweet thisAlerts:
@VladdyMay 12.2005 — Validation of an e-mail is a waste of time and effort.

"[email protected]" is an absolutely valid e-mail but it would do you as much good as "#$%*&"

You can have a user-friendliness feature that prompts them if e-mail field data does not have proper syntax, but then save them an aggrivation of having to type it twice (most actually do Ctrl+C - Ctrl+V making the matching of the two fields once again pointless)
Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — The best way to validate email addresses is to use a server-side program to dispatch an email to them with a link for them to click on that will confirm the email address.

The link might look something like this:

ht[b][/b]tp://www.mywebsite.com/cgi-bin/confirmer.php?hash=f04029e9B9d09ef9e00

Thus, when the link is clicked, that query string is sent to the PHP program and will try to match that hash with the hash of an email address awaiting to be confirmed. Then when the email is confirmed the user's profile is updated and their email address is verified otherwise it would remain un-verified.

You can even make the PHP program delete hashes from it's awaiting-email- address-to-be-verified list after a period of time -- say 1 month.
Copy linkTweet thisAlerts:
@mikewootenauthorMay 12.2005 — ok thanks, that works, but where do i point the form to? where in the form would i point to the next page like anotherpage.html after clicking submit?

i need to point to the next page, where would i do that?

thanks
Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — Note: It is possible to provide a phony email address and verify it by calculating the hash that would be generated and entering the link manually.

I haven't tried doing this before though, but I should give it a shot once and see if I can bypass some security, just to see how secure it is.

It's best to use hash generaters that use random numbers rather than algorithms to generate the hashes.
Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — change:

action="javascript:void(alert('submit form'))"

into:

action="anotherpage.html"
Copy linkTweet thisAlerts:
@mikewootenauthorMay 12.2005 — ok thanks, so how would i do that using javascript?

thanks
Copy linkTweet thisAlerts:
@UltimaterMay 12.2005 — What, validating email addresses? That cannot be done with JavaScript.

You'd need a server-side program to do that.

Try learning a server-side language to do that.

I'd suggest PHP.

The server-side program extensions are:

cgi, pl, asp, php, cfm, aspx [b]and there are way more...[/b]

The name of the programming languages are all the same except for:

pl which is called PERL and cfm which is called Could Fussion.

I'd strongly suggest PHP.
×

Success!

Help @mikewooten spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...