<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.css?cache=2026-11-13T15:19:59+00:00" type="text/css"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<html:meta xmlns:html="http://www.w3.org/1999/xhtml" name="viewport" content="width=device-width" />
<channel>
	<title>notemail &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/notemail/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Fri, 27 Sep 2024 05:55:03 +0000</lastBuildDate>
	<language>en-GB</language>
	<copyright>© Terence Eden. 🄯 CC BY-SA. See https://shkspr.mobi/blog/copyright-and-copyleft/</copyright>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>notemail &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[How to check something isn't an email address?]]></title>
		<link>https://shkspr.mobi/blog/2023/09/how-to-check-something-isnt-an-email-address/</link>
					<comments>https://shkspr.mobi/blog/2023/09/how-to-check-something-isnt-an-email-address/#comments</comments>
				<dc:creator><![CDATA[Terence Eden]]></dc:creator>
		<pubDate>Wed, 27 Sep 2023 11:34:39 +0000</pubDate>
		<category><![CDATA[HTML5]]></category><category><![CDATA[notemail]]></category>		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=47236</guid>

		
		<description>In web-development circles, it is a well-known fact that trying to validate an email using a regular expression is… complex.  The full set of modern email standards allows for such wonderful addresses as: chief.o'brien+ds9@spásárthach.भारत  So determining whether or not your user has entered a valid email address becomes an ever-increasing challenge.  But what if you have the opposite issue? Suppo…</description>
			
		<content:encoded>&lt;p&gt;In web-development circles, it is a well-known fact that trying to &lt;a href="https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression"&gt;validate an email using a regular expression&lt;/a&gt; is… complex.&lt;/p&gt;

&lt;p&gt;The full set of modern email standards allows for such wonderful addresses as:
&lt;code&gt;chief.o'brien+ds9@spásárthach.भारत&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So determining whether or not your user has entered a valid email address becomes an ever-increasing challenge.&lt;/p&gt;

&lt;p&gt;But what if you have the opposite issue? Suppose you have a form which takes something which &lt;em&gt;mustn't&lt;/em&gt; be an email address?&lt;/p&gt;

&lt;p&gt;For example - imagine you have a login form which requires a username. And yet your stupid users keep entering their email addresses instead!  How can you quickly, cheaply, and simply detect email addresses?&lt;/p&gt;

&lt;p&gt;Well, no matter whatever else is in an email address, there will &lt;em&gt;always&lt;/em&gt; be an &lt;code&gt;@&lt;/code&gt; somewhere. The &lt;code&gt;@&lt;/code&gt; is &lt;a href="https://www.khanacademy.org/test-prep/lsat/lsat-lessons/logic-toolbox-new/a/logic-toolbox--article--if-x-then-y--sufficiency-and-necessity"&gt;&lt;em&gt;necessary&lt;/em&gt; but not &lt;em&gt;sufficient&lt;/em&gt;&lt;/a&gt; for an email address.&lt;/p&gt;

&lt;p&gt;So you can use &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/pattern"&gt;HTML5's &lt;code&gt;pattern&lt;/code&gt; attribute&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here it is in action:&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-html"&gt;&amp;lt;input type="text" 
       pattern="^[^@]+$"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That says "don't accept anything with the &lt;code&gt;@&lt;/code&gt; symbol in it".&lt;/p&gt;

&lt;p&gt;We can take it a bit further and add some more attributes to help our users&lt;/p&gt;

&lt;pre&gt;&lt;code class="language-html"&gt;&amp;lt;input type="text" 
       pattern="^[^@]+$"
       required
       placeholder="Your username (which is NOT your email address)"
       title="Don't use your email address!!!!!"
       id="notemail"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;h2 id="try-it-out"&gt;&lt;a href="https://shkspr.mobi/blog/2023/09/how-to-check-something-isnt-an-email-address/#try-it-out"&gt;Try it out!&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;As soon as you type an &lt;code&gt;@&lt;/code&gt; the form will go into an invalid state and can't be submitted. You won't be able to click the login button.&lt;/p&gt;

&lt;form action=""&gt;
&lt;input type="text" pattern="^[^@]+$" required="" placeholder="Your username (which isn't your email address)" title="Don't use your email address!!!!!" id="notemail"&gt;&lt;input type="submit" value="Log In"&gt;
&lt;style&gt;#notemail:valid {background-color: #0f0;} #notemail:invalid { border: #f00 solid 5px;}&lt;/style&gt;
&lt;/form&gt;

&lt;h2 id="should-you-use-this"&gt;&lt;a href="https://shkspr.mobi/blog/2023/09/how-to-check-something-isnt-an-email-address/#should-you-use-this"&gt;Should You Use This?&lt;/a&gt;&lt;/h2&gt;

&lt;p&gt;Well… perhaps in a pinch. The &lt;em&gt;real&lt;/em&gt; solution is to be agnostic towards your users' choice of login. Some may prefer to use an email, some a username. Some may expect their username to &lt;em&gt;start&lt;/em&gt; with an &lt;code&gt;@&lt;/code&gt;. Be tolerant of their needs and desires.&lt;/p&gt;
&lt;img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=47236&amp;amp;HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager"&gt;</content:encoded>
	

					<wfw:commentRss>https://shkspr.mobi/blog/2023/09/how-to-check-something-isnt-an-email-address/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
