email-validation http://www.e-learn.cn/tag/email-validation zh-hans Can there be an apostrophe in an email address? [duplicate] http://www.e-learn.cn/topic/4057943 <span>Can there be an apostrophe in an email address? [duplicate]</span> <span><span lang="" about="/user/228" typeof="schema:Person" property="schema:name" datatype="">故事扮演</span></span> <span>2021-02-05 20:41:14</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell wmn0 fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt8">Closed <span title="2011-12-15 22:25:48Z" class="relativetime">9 years ago</span>.</div> </div> </aside></div> <blockquote> <p><strong>Possible Duplicate:</strong><br /> What characters are allowed in email address? </p> </blockquote> <p>I have an email address with an apostrophe in it and am wondering if that is valid?</p> <br /><h3>回答1:</h3><br /><p>Yes, according to RFC 3696 apostrophes are valid as long as they come before the @ symbol.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/8527180/can-there-be-an-apostrophe-in-an-email-address</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/email" hreflang="zh-hans">email</a></div> <div class="field--item"><a href="/tag/email-integration" hreflang="zh-hans">email-integration</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Fri, 05 Feb 2021 12:41:14 +0000 故事扮演 4057943 at http://www.e-learn.cn How to check if email actually exists http://www.e-learn.cn/topic/4048361 <span>How to check if email actually exists</span> <span><span lang="" about="/user/45" typeof="schema:Person" property="schema:name" datatype="">妖精的绣舞</span></span> <span>2021-02-04 13:43:50</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I created a form in which you have to insert an email address.</p> <p>I already have a validation method. But i need to make sure that the email actually exists.</p> <p>Is it possible?</p> <br /><h3>回答1:</h3><br /><p>In the general case it is not possible without user interaction.</p> <p>A few things you can do to validate an email address:</p> <h3>Regular expression</h3> <p>You can use a regex to validate the email address <em>format</em>. It does not guarantee that the address exists, but at least your user input will be well formed. Validating email addresses by a regular expression is not straightforward though, see here for difficulties. You can find guidelines here.</p> <h3>DNS lookup</h3> <p>Once the address is well-formed, you can check with a simple DNS query whether the domain name actually exists and has an associated MX record. If it does not, the email is obviously invalid. If it does, it can still be <em>any</em> valid domain, and there is no proof that there actually is a valid user of the name specified on that domain.</p> <h3>VRFY</h3> <p>If the domain exists, you can issue an SMTP VRFY command to the smtp server read from the MX record of the domain. VRFY will tell you whether the user name (the part before @) is a valid email address on that server. The caveat is that some server will not tell you the truth and deny all usernames or not implement the VRFY command as it is a security risk (in many cases, email accounts are valid usernames for the server, so this would allow username enumeration).</p> <p>So if a VRFY command tells you the address is valid, there is a good chance that it really is. If it tells you it is not valid or VRFY is not implemented on the SMTP server, you basically gained no info. Because of this, you may not want to do this at all.</p> <p>More info on this is here and here (among many others).</p> <h3>Sending a confirmation email</h3> <p>Ultimately, you should send a confirmation email with a one-time token to the given email address, and store that token in your database for future reference. If the user can click a link in the email sent (ie. can send the token back), he proves that the email address is valid and it actually belongs to him.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/40666872/how-to-check-if-email-actually-exists</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/java" hreflang="zh-hans">java</a></div> <div class="field--item"><a href="/tag/android" hreflang="zh-hans">android</a></div> <div class="field--item"><a href="/tag/email" hreflang="zh-hans">email</a></div> <div class="field--item"><a href="/tag/security" hreflang="zh-hans">security</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Thu, 04 Feb 2021 05:43:50 +0000 妖精的绣舞 4048361 at http://www.e-learn.cn find email using regular expression python [duplicate] http://www.e-learn.cn/topic/3717025 <span>find email using regular expression python [duplicate]</span> <span><span lang="" about="/user/24" typeof="schema:Person" property="schema:name" datatype="">Deadly</span></span> <span>2020-08-06 07:11:55</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> How to validate an email address using a regular expression? <span class="question-originals-answer-count"> (74 answers) </span> </div> <div class="grid--cell mb0 mt4"> How to check for valid email address? [duplicate] <span class="question-originals-answer-count"> (18 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2019-02-26 16:46:09Z" class="relativetime">last year</span>.</div> </div> </aside></div> <p>I want to find valid email addresses in a text file, and this is my code:</p> <pre><code>email = re.findall(r'[a-zA-Z\.-]+@[\w\.-]+',line) </code></pre> <p>But my code obviously does not contain email addresses where there are numbers before @ sign. And my code could not handle email addresses that do not have valid ending. So could anyone help me with these two problems? Thank you!</p> <p>An example of my problem would be:</p> <p>my code can find this email: xyz@gmail.com</p> <p>but it cannot find this one: xyz123@gmail.com</p> <p>And it cannot filter this email out either: xyz@gmail</p> <br /><h3>回答1:</h3><br /><p>From the python re docs, <code>\w</code> matches any alphanumeric character and underscores, equivalent to the set <code>[a-zA-Z0-9_]</code>. So <code>[\w\.-]</code> will appropriately match numbers as well as characters.</p> <pre><code>email = re.findall(r'[\w\.-]+@[\w\.-]+(\.[\w]+)+',line) </code></pre> <p>This post discusses matching email addresses much more extensively, and there are a couple more pitfalls you run into matching email addresses that your code fails to catch. For example, email addresses cannot be made up entirely of punctuation (<code>...@....</code>). Additionally, there is often a maximum length on addresses, depending on the email server. Also, many email servers match non-english characters. So depending on your needs you may need a more comprehensive pattern.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Try the <code>validate_email</code> package.</p> <pre><code>pip install validate_email </code></pre> <p>Then</p> <pre><code>from validate_email import validate_email is_valid = validate_email('example@example.com') </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><pre><code>^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ </code></pre> <p>Not mine, but I have used it in apps before.</p> <p>Source</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/41798539/find-email-using-regular-expression-python</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/regex" hreflang="zh-hans">regex</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Wed, 05 Aug 2020 23:11:55 +0000 Deadly 3717025 at http://www.e-learn.cn find email using regular expression python [duplicate] http://www.e-learn.cn/topic/3717020 <span>find email using regular expression python [duplicate]</span> <span><span lang="" about="/user/7" typeof="schema:Person" property="schema:name" datatype="">▼魔方 西西</span></span> <span>2020-08-06 07:10:53</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> How to validate an email address using a regular expression? <span class="question-originals-answer-count"> (74 answers) </span> </div> <div class="grid--cell mb0 mt4"> How to check for valid email address? [duplicate] <span class="question-originals-answer-count"> (18 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2019-02-26 16:46:09Z" class="relativetime">last year</span>.</div> </div> </aside></div> <p>I want to find valid email addresses in a text file, and this is my code:</p> <pre><code>email = re.findall(r'[a-zA-Z\.-]+@[\w\.-]+',line) </code></pre> <p>But my code obviously does not contain email addresses where there are numbers before @ sign. And my code could not handle email addresses that do not have valid ending. So could anyone help me with these two problems? Thank you!</p> <p>An example of my problem would be:</p> <p>my code can find this email: xyz@gmail.com</p> <p>but it cannot find this one: xyz123@gmail.com</p> <p>And it cannot filter this email out either: xyz@gmail</p> <br /><h3>回答1:</h3><br /><p>From the python re docs, <code>\w</code> matches any alphanumeric character and underscores, equivalent to the set <code>[a-zA-Z0-9_]</code>. So <code>[\w\.-]</code> will appropriately match numbers as well as characters.</p> <pre><code>email = re.findall(r'[\w\.-]+@[\w\.-]+(\.[\w]+)+',line) </code></pre> <p>This post discusses matching email addresses much more extensively, and there are a couple more pitfalls you run into matching email addresses that your code fails to catch. For example, email addresses cannot be made up entirely of punctuation (<code>...@....</code>). Additionally, there is often a maximum length on addresses, depending on the email server. Also, many email servers match non-english characters. So depending on your needs you may need a more comprehensive pattern.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Try the <code>validate_email</code> package.</p> <pre><code>pip install validate_email </code></pre> <p>Then</p> <pre><code>from validate_email import validate_email is_valid = validate_email('example@example.com') </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><pre><code>^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ </code></pre> <p>Not mine, but I have used it in apps before.</p> <p>Source</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/41798539/find-email-using-regular-expression-python</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/regex" hreflang="zh-hans">regex</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Wed, 05 Aug 2020 23:10:53 +0000 ▼魔方 西西 3717020 at http://www.e-learn.cn find email using regular expression python [duplicate] http://www.e-learn.cn/topic/3717017 <span>find email using regular expression python [duplicate]</span> <span><span lang="" about="/user/107" typeof="schema:Person" property="schema:name" datatype="">守給你的承諾、</span></span> <span>2020-08-06 07:10:09</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><div> <aside class="s-notice s-notice__info js-post-notice mb16" role="status"><div class="grid fd-column fw-nowrap"> <div class="grid fw-nowrap"> <div class="grid--cell fl1 lh-lg"> <div class="grid--cell fl1 lh-lg"> <b>This question already has answers here</b>: </div> </div> </div> <div class="grid--cell mb0 mt4"> How to validate an email address using a regular expression? <span class="question-originals-answer-count"> (74 answers) </span> </div> <div class="grid--cell mb0 mt4"> How to check for valid email address? [duplicate] <span class="question-originals-answer-count"> (18 answers) </span> </div> <div class="grid--cell mb0 mt8">Closed <span title="2019-02-26 16:46:09Z" class="relativetime">last year</span>.</div> </div> </aside></div> <p>I want to find valid email addresses in a text file, and this is my code:</p> <pre><code>email = re.findall(r'[a-zA-Z\.-]+@[\w\.-]+',line) </code></pre> <p>But my code obviously does not contain email addresses where there are numbers before @ sign. And my code could not handle email addresses that do not have valid ending. So could anyone help me with these two problems? Thank you!</p> <p>An example of my problem would be:</p> <p>my code can find this email: xyz@gmail.com</p> <p>but it cannot find this one: xyz123@gmail.com</p> <p>And it cannot filter this email out either: xyz@gmail</p> <br /><h3>回答1:</h3><br /><p>From the python re docs, <code>\w</code> matches any alphanumeric character and underscores, equivalent to the set <code>[a-zA-Z0-9_]</code>. So <code>[\w\.-]</code> will appropriately match numbers as well as characters.</p> <pre><code>email = re.findall(r'[\w\.-]+@[\w\.-]+(\.[\w]+)+',line) </code></pre> <p>This post discusses matching email addresses much more extensively, and there are a couple more pitfalls you run into matching email addresses that your code fails to catch. For example, email addresses cannot be made up entirely of punctuation (<code>...@....</code>). Additionally, there is often a maximum length on addresses, depending on the email server. Also, many email servers match non-english characters. So depending on your needs you may need a more comprehensive pattern.</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Try the <code>validate_email</code> package.</p> <pre><code>pip install validate_email </code></pre> <p>Then</p> <pre><code>from validate_email import validate_email is_valid = validate_email('example@example.com') </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><pre><code>^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ </code></pre> <p>Not mine, but I have used it in apps before.</p> <p>Source</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/41798539/find-email-using-regular-expression-python</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/python" hreflang="zh-hans">python</a></div> <div class="field--item"><a href="/tag/regex" hreflang="zh-hans">regex</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Wed, 05 Aug 2020 23:10:09 +0000 守給你的承諾、 3717017 at http://www.e-learn.cn Is it correct that sometimes I get angle brackets in “From” field of an e-mail message? http://www.e-learn.cn/topic/3680816 <span>Is it correct that sometimes I get angle brackets in “From” field of an e-mail message?</span> <span><span lang="" about="/user/146" typeof="schema:Person" property="schema:name" datatype="">狂风中的少年</span></span> <span>2020-07-05 03:08:56</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>My software is working with incoming e-mail from the one and only particular sender (let it be SantaClaus@hetnet.nl). According to RFC-2616 section 14 "From" header </p> <blockquote> <p>MAY be used for logging purposes and <strong>as a means for identifying the source of invalid or unwanted requests.</strong></p> </blockquote> <p>That's exactly what I needed, so I wrote a code, which ignores all the messages where "From" field doesn't equal <code>SantaClaus@hetnet.nl</code>. It worked good, but one day things changed, and now all the messages form Santa Claus contains a different string in "From" field (exactly <code>&lt;SantaClaus@hetnet.nl&gt;</code>). I already fixed my code, but I just wonder, is this header legal? Because the same RFC-2616 section 14 says: </p> <blockquote> <p>The address SHOULD be machine-usable, as defined by "mailbox" in RFC 822 [9] as updated by RFC 1123 [8]:</p> <pre><code> From = "From" ":" mailbox </code></pre> <p>An example is:</p> <pre><code> From: webmaster@w3.org </code></pre> </blockquote> <p>Note the absense of angle brackets. But at the same time, many e-mail messages I receive on my Gmail account has something like this in the "From" field: <code>"Santa Claus" &lt;santaclaus@hetnet.nl&gt;</code></p> <br /><h3>回答1:</h3><br /><p>RFC-822 allows email addresses to be specified either by a pure email-style address, called an "<em>addr-spec</em>" (e.g., <code>name@host.domain</code>); or by using a nickname ("<em>phrase</em>") with the email-style address (the "<em>addr-spec</em>") enclosed in angle brackets (<code>Foo Bar &lt;foobar@host.domain&gt;</code>). Your sender has gone from the first format to the second format, although here the nickname part seems to be empty.</p> <p>By the way, RFC-2616 is for HTTP; you're looking at the definition of an optional, and (I imagine) rarely-used, From: header in the HTTP protocol. That doesn't seem to have any direct relevance on email formats.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/4473804/is-it-correct-that-sometimes-i-get-angle-brackets-in-from-field-of-an-e-mail-m</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/email" hreflang="zh-hans">email</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Sat, 04 Jul 2020 19:08:56 +0000 狂风中的少年 3680816 at http://www.e-learn.cn Is it correct that sometimes I get angle brackets in “From” field of an e-mail message? http://www.e-learn.cn/topic/3680813 <span>Is it correct that sometimes I get angle brackets in “From” field of an e-mail message?</span> <span><span lang="" about="/user/93" typeof="schema:Person" property="schema:name" datatype="">送分小仙女□</span></span> <span>2020-07-05 03:08:11</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>My software is working with incoming e-mail from the one and only particular sender (let it be SantaClaus@hetnet.nl). According to RFC-2616 section 14 "From" header </p> <blockquote> <p>MAY be used for logging purposes and <strong>as a means for identifying the source of invalid or unwanted requests.</strong></p> </blockquote> <p>That's exactly what I needed, so I wrote a code, which ignores all the messages where "From" field doesn't equal <code>SantaClaus@hetnet.nl</code>. It worked good, but one day things changed, and now all the messages form Santa Claus contains a different string in "From" field (exactly <code>&lt;SantaClaus@hetnet.nl&gt;</code>). I already fixed my code, but I just wonder, is this header legal? Because the same RFC-2616 section 14 says: </p> <blockquote> <p>The address SHOULD be machine-usable, as defined by "mailbox" in RFC 822 [9] as updated by RFC 1123 [8]:</p> <pre><code> From = "From" ":" mailbox </code></pre> <p>An example is:</p> <pre><code> From: webmaster@w3.org </code></pre> </blockquote> <p>Note the absense of angle brackets. But at the same time, many e-mail messages I receive on my Gmail account has something like this in the "From" field: <code>"Santa Claus" &lt;santaclaus@hetnet.nl&gt;</code></p> <br /><h3>回答1:</h3><br /><p>RFC-822 allows email addresses to be specified either by a pure email-style address, called an "<em>addr-spec</em>" (e.g., <code>name@host.domain</code>); or by using a nickname ("<em>phrase</em>") with the email-style address (the "<em>addr-spec</em>") enclosed in angle brackets (<code>Foo Bar &lt;foobar@host.domain&gt;</code>). Your sender has gone from the first format to the second format, although here the nickname part seems to be empty.</p> <p>By the way, RFC-2616 is for HTTP; you're looking at the definition of an optional, and (I imagine) rarely-used, From: header in the HTTP protocol. That doesn't seem to have any direct relevance on email formats.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/4473804/is-it-correct-that-sometimes-i-get-angle-brackets-in-from-field-of-an-e-mail-m</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/email" hreflang="zh-hans">email</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Sat, 04 Jul 2020 19:08:11 +0000 送分小仙女□ 3680813 at http://www.e-learn.cn C# Prepared Statements - @ sign (at / strudel sign) queries http://www.e-learn.cn/topic/3327715 <span>C# Prepared Statements - @ sign (at / strudel sign) queries</span> <span><span lang="" about="/user/182" typeof="schema:Person" property="schema:name" datatype="">南笙酒味</span></span> <span>2020-01-29 12:33:45</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I Have a problem with a prepared statement in C#:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = ?"; cmd.Parameters.Add("@USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <p>(of course email contains a valid email address, with @ sign).</p> <p>This code returns a random error - </p> <blockquote> <p>"The connection has been disabled" {"ERROR [01000] [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionWrite (send()). ERROR [08S01] [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]General network error. Check your network documentation."}</p> </blockquote> <p>However if I run my code without a prepared statement, meaning:</p> <pre><code>cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = '"+email+"'"; </code></pre> <p>Everything works perfectly.</p> <p>Maybe it's related to the fact that I have a @ sign in the parametrized value? I tend to think I'm not the first one trying to create a prepared statement with an email address...</p> <p>I have no idea what's wrong! Other prepared statements work normally...</p> <p>Can you please help? :) Thanks, Nili</p> <br /><h3>回答1:</h3><br /><p>Indeed, ODBC has its share of issues with supporting named parameters. However, certain usage of named parameters is possible.</p> <p>For example, in your case the following syntax works:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = ?"; cmd.Parameters.Add("USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <p>More tricky situation is when you don't have a unique match for the parameter like USER_ID = ?; e.g., when you want to use the <em>IN</em> operator in the <em>WHERE</em> clause.</p> <p>Then the following syntax would do the job:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID IN (?, ?)"; cmd.Parameters.Add("?ID1", OdbcType.VarChar, 250).Value = email1; cmd.Parameters.Add("?ID2", OdbcType.VarChar, 250).Value = email2; </code></pre> <p>Please note the usage of <strong>?</strong> (question mark) instead of <strong>@</strong> (at sign) within the parameter name. Although note that substitution of parameters' values in this case has nothing to do with their names, but only with their order with the parameters collection.</p> <p>I hope this helps :-)</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Use '@USER_ID' instead of '?' and all should work:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = @USER_ID"; cmd.Parameters.Add("@USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Is there a specific reason you're using <code>OdbcCommand</code> rather than using the <code>SqlClient</code> provider?</p> <p>With the <code>SqlClient</code> provider, you should be using named parameters as others have suggested.</p> <p>But according to MSDN:</p> <blockquote> <p>The .NET Framework Data Provider for OLE DB and .NET Framework Data Provider for ODBC do not support named parameters for passing parameters to an SQL statement or a stored procedure. In this case, you must use the question mark (?) placeholder, as in the following example.</p> </blockquote> <p>So I'm not sure named parameters will work in this case.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/4954877/c-sharp-prepared-statements-sign-at-strudel-sign-queries</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/sql-server-2005" hreflang="zh-hans">sql-server-2005</a></div> <div class="field--item"><a href="/tag/prepared-statement" hreflang="zh-hans">prepared-statement</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Wed, 29 Jan 2020 04:33:45 +0000 南笙酒味 3327715 at http://www.e-learn.cn C# Prepared Statements - @ sign (at / strudel sign) queries http://www.e-learn.cn/topic/3327714 <span>C# Prepared Statements - @ sign (at / strudel sign) queries</span> <span><span lang="" about="/user/184" typeof="schema:Person" property="schema:name" datatype="">柔情痞子</span></span> <span>2020-01-29 12:32:35</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I Have a problem with a prepared statement in C#:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = ?"; cmd.Parameters.Add("@USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <p>(of course email contains a valid email address, with @ sign).</p> <p>This code returns a random error - </p> <blockquote> <p>"The connection has been disabled" {"ERROR [01000] [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]ConnectionWrite (send()). ERROR [08S01] [Microsoft][ODBC SQL Server Driver][TCP/IP Sockets]General network error. Check your network documentation."}</p> </blockquote> <p>However if I run my code without a prepared statement, meaning:</p> <pre><code>cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = '"+email+"'"; </code></pre> <p>Everything works perfectly.</p> <p>Maybe it's related to the fact that I have a @ sign in the parametrized value? I tend to think I'm not the first one trying to create a prepared statement with an email address...</p> <p>I have no idea what's wrong! Other prepared statements work normally...</p> <p>Can you please help? :) Thanks, Nili</p> <br /><h3>回答1:</h3><br /><p>Indeed, ODBC has its share of issues with supporting named parameters. However, certain usage of named parameters is possible.</p> <p>For example, in your case the following syntax works:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = ?"; cmd.Parameters.Add("USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <p>More tricky situation is when you don't have a unique match for the parameter like USER_ID = ?; e.g., when you want to use the <em>IN</em> operator in the <em>WHERE</em> clause.</p> <p>Then the following syntax would do the job:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID IN (?, ?)"; cmd.Parameters.Add("?ID1", OdbcType.VarChar, 250).Value = email1; cmd.Parameters.Add("?ID2", OdbcType.VarChar, 250).Value = email2; </code></pre> <p>Please note the usage of <strong>?</strong> (question mark) instead of <strong>@</strong> (at sign) within the parameter name. Although note that substitution of parameters' values in this case has nothing to do with their names, but only with their order with the parameters collection.</p> <p>I hope this helps :-)</p> <br /><br /><br /><h3>回答2:</h3><br /><p>Use '@USER_ID' instead of '?' and all should work:</p> <pre><code>OdbcCommand cmd = sql.CreateCommand(); cmd.CommandText = "SELECT UNIQUE_ID FROM userdetails WHERE USER_ID = @USER_ID"; cmd.Parameters.Add("@USER_ID", OdbcType.VarChar, 250).Value = email; </code></pre> <br /><br /><br /><h3>回答3:</h3><br /><p>Is there a specific reason you're using <code>OdbcCommand</code> rather than using the <code>SqlClient</code> provider?</p> <p>With the <code>SqlClient</code> provider, you should be using named parameters as others have suggested.</p> <p>But according to MSDN:</p> <blockquote> <p>The .NET Framework Data Provider for OLE DB and .NET Framework Data Provider for ODBC do not support named parameters for passing parameters to an SQL statement or a stored procedure. In this case, you must use the question mark (?) placeholder, as in the following example.</p> </blockquote> <p>So I'm not sure named parameters will work in this case.</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/4954877/c-sharp-prepared-statements-sign-at-strudel-sign-queries</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/c" hreflang="zh-hans">c#</a></div> <div class="field--item"><a href="/tag/sql" hreflang="zh-hans">sql</a></div> <div class="field--item"><a href="/tag/sql-server-2005" hreflang="zh-hans">sql-server-2005</a></div> <div class="field--item"><a href="/tag/prepared-statement" hreflang="zh-hans">prepared-statement</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Wed, 29 Jan 2020 04:32:35 +0000 柔情痞子 3327714 at http://www.e-learn.cn JavaScript verify email by SMTP http://www.e-learn.cn/topic/3314405 <span>JavaScript verify email by SMTP</span> <span><span lang="" about="/user/156" typeof="schema:Person" property="schema:name" datatype="">微笑、不失礼</span></span> <span>2020-01-26 04:21:06</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><h3>问题</h3><br /><p>I would like to enable my website form to check if the email inserted by my visitor is valid and exist before allowing them submit the web form.</p> <p>I do understand there is many Javascript to check the email pattern validation. But I need something such as SMTP Email Checking or Validating.</p> <p>The email inserted by visitor must be valid format and also existed, this is to prevent visitor inserts invalid email, incorrect email address, as well as spamming email address.</p> <p>Please kindly provide a tutorial link for validate the Email by using Javascript.</p> <p>I believe server-side scripting can doing it, but I need an instant response to the web form before web visitor select the submit button for form submission. </p> <br /><h3>回答1:</h3><br /><p>There is no point just checking if an email is "valid" without confirming that your user "owns" that email account. So therefore the only way to confirm an email address is valid AND is actually owned by that user is to send them a verification email.</p> <p>In your email you'll include a unique code, and store that in the database.</p> <p>Then in the email get them to click on the link to your website where you validate the unique code. This allows you to confirm the email address.</p> <p>Once the user has confirmed their email address - then let them login into your site</p> <br /><br /><p>来源:<code>https://stackoverflow.com/questions/12174029/javascript-verify-email-by-smtp</code></p></div> <div class="field field--name-field-tags field--type-entity-reference field--label-above"> <div class="field--label">标签</div> <div class="field--items"> <div class="field--item"><a href="/tag/php" hreflang="zh-hans">php</a></div> <div class="field--item"><a href="/tag/javascript" hreflang="zh-hans">javascript</a></div> <div class="field--item"><a href="/tag/email" hreflang="zh-hans">email</a></div> <div class="field--item"><a href="/tag/smtp" hreflang="zh-hans">smtp</a></div> <div class="field--item"><a href="/tag/email-validation" hreflang="zh-hans">email-validation</a></div> </div> </div> Sat, 25 Jan 2020 20:21:06 +0000 微笑、不失礼 3314405 at http://www.e-learn.cn