<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<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/"
	>
<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>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.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[@edent]]></dc:creator>
		<pubDate>Wed, 27 Sep 2023 11:34:39 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[notemail]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=47236</guid>

					<description><![CDATA[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&#039;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><![CDATA[<p>In web-development circles, it is a well-known fact that trying to <a href="https://stackoverflow.com/questions/201323/how-can-i-validate-an-email-address-using-a-regular-expression">validate an email using a regular expression</a> is… complex.</p>

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

<p>So determining whether or not your user has entered a valid email address becomes an ever-increasing challenge.</p>

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

<p>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?</p>

<p>Well, no matter whatever else is in an email address, there will <em>always</em> be an <code>@</code> somewhere. The <code>@</code> is <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"><em>necessary</em> but not <em>sufficient</em></a> for an email address.</p>

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

<p>Here it is in action:</p>

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

<p>That says "don't accept anything with the <code>@</code> symbol in it".</p>

<p>We can take it a bit further and add some more attributes to help our users</p>

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

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

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

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

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

<p>Well… perhaps in a pinch. The <em>real</em> 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 <em>start</em> with an <code>@</code>. Be tolerant of their needs and desires.</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=47236&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></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>
