{"id":736,"date":"2004-07-20T12:26:54","date_gmt":"2004-07-20T12:26:54","guid":{"rendered":"http:\/\/beta.robertprice.co.uk\/robblog\/2004\/07\/comparing_email_addresses_in_javascript-shtml\/"},"modified":"2004-07-20T12:26:54","modified_gmt":"2004-07-20T12:26:54","slug":"comparing_email_addresses_in_javascript-shtml","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/","title":{"rendered":"Comparing Email Addresses In JavaScript"},"content":{"rendered":"<p>\nI needed to write a quick JavaScript that could check if two email addresses were the same or not today. As it&#8217;s so simple, I thought I&#8217;d share it.\n<\/p>\n<p>\nFirstly we put the following JavaScript into a <code>script<\/code> tag.\n<\/p>\n<pre class=\"lang:js decode:true \" >function compareEmails(myForm) {\n  if (myForm.email.value != myForm.email2.value) {\n    alert(\"Your email addresses don't match. Please double check\");\n    return false;\n  } else {\n    return true;\n  }\n}\n<\/pre>\n<p>\nIt takes a form, and compares the values of the fields called <code>email<\/code> and <code>email2<\/code>. If they are the same it returns <code>true<\/code> which lets the form submit normally.\n<\/p>\n<p>\nHowever, if <code>email<\/code> and <code>email2<\/code> are different it brings up an alert box telling our submitter the values are different, and returns false. Returning false means the script won&#8217;t submit to the script specified in the <code>action<\/code> parameter so the user has to confirm their email address again.\n<\/p>\n<p>\nThe following <acronym title=\"HyperText Markup Language\">HTML<\/acronym> code gives an example of the scripts use.\n<\/p>\n<pre class=\"lang:html decode:true \" >\n&lt;form action=\"dosomething.pl\" onSubmit=\"compareEmails(this);\"&gt;\nEmail :&lt;input type=\"text\" name=\"email\" \/&gt; &lt;br \/&gt;\nVerify Email: &lt;input type=\"text\" name=\"email2\" \/&gt; &lt;br \/&gt;\n&lt;input type=\"submit\" \/&gt;\n&lt;\/form&gt;\n<\/pre>\n<p>\nOf course the code can be used to compare any fields and not just email addresses. All you need to do is to change the field names in the JavaScript.\n<\/p>\n<p>\nEnjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I needed to write a quick JavaScript that could check if two email addresses were the same or not today. As it&#8217;s so simple, I thought I&#8217;d share it. Firstly we put the following JavaScript into a script tag. function compareEmails(myForm) { if (myForm.email.value != myForm.email2.value) { alert(&#8220;Your email addresses don&#8217;t match. Please double check&#8221;); &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Comparing Email Addresses In JavaScript&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[31],"class_list":["post-736","post","type-post","status-publish","format-standard","hentry","category-dev","tag-javascript"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Comparing Email Addresses In JavaScript - Robert Price<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comparing Email Addresses In JavaScript - Robert Price\" \/>\n<meta property=\"og:description\" content=\"I needed to write a quick JavaScript that could check if two email addresses were the same or not today. As it&#8217;s so simple, I thought I&#8217;d share it. Firstly we put the following JavaScript into a script tag. function compareEmails(myForm) { if (myForm.email.value != myForm.email2.value) { alert(&quot;Your email addresses don&#039;t match. Please double check&quot;); &hellip; Continue reading &quot;Comparing Email Addresses In JavaScript&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2004-07-20T12:26:54+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Comparing Email Addresses In JavaScript\",\"datePublished\":\"2004-07-20T12:26:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/\"},\"wordCount\":159,\"keywords\":[\"JavaScript\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/\",\"name\":\"Comparing Email Addresses In JavaScript - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2004-07-20T12:26:54+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/comparing_email_addresses_in_javascript-shtml\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Comparing Email Addresses In JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comparing Email Addresses In JavaScript - Robert Price","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/","og_locale":"en_GB","og_type":"article","og_title":"Comparing Email Addresses In JavaScript - Robert Price","og_description":"I needed to write a quick JavaScript that could check if two email addresses were the same or not today. As it&#8217;s so simple, I thought I&#8217;d share it. Firstly we put the following JavaScript into a script tag. function compareEmails(myForm) { if (myForm.email.value != myForm.email2.value) { alert(\"Your email addresses don't match. Please double check\"); &hellip; Continue reading \"Comparing Email Addresses In JavaScript\"","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/","og_site_name":"Robert Price","article_published_time":"2004-07-20T12:26:54+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Comparing Email Addresses In JavaScript","datePublished":"2004-07-20T12:26:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/"},"wordCount":159,"keywords":["JavaScript"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/","name":"Comparing Email Addresses In JavaScript - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2004-07-20T12:26:54+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/comparing_email_addresses_in_javascript-shtml\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Comparing Email Addresses In JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=736"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/736\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}