Popular recipes tagged "validating"http://code.activestate.com/recipes/tags/validating/popular/2011-08-11T19:06:58-07:00ActiveState Code RecipesCredit Card Validation (Python)
2011-08-11T19:06:58-07:00Stijn de Graafhttp://code.activestate.com/recipes/users/4178055/http://code.activestate.com/recipes/577838-credit-card-validation/
<p style="color: grey">
Python
recipe 577838
by <a href="/recipes/users/4178055/">Stijn de Graaf</a>
(<a href="/recipes/tags/card/">card</a>, <a href="/recipes/tags/credit/">credit</a>, <a href="/recipes/tags/false/">false</a>, <a href="/recipes/tags/number/">number</a>, <a href="/recipes/tags/testing/">testing</a>, <a href="/recipes/tags/true/">true</a>, <a href="/recipes/tags/validating/">validating</a>, <a href="/recipes/tags/validation/">validation</a>).
</p>
<p>Test validity of any credit card number using the LUHN method (mod 10).
Starting at the last digit and moving backwards, you add up every other digit.
Then, you double the left-out digits, and add the digits of these results to the original sum.
If this satisfies sum mod 10 == 0 then the card is valid.</p>
<p>This is also explained at <a href="http://www.beachnet.com/%7Ehstiles/cardtype.html" rel="nofollow">http://www.beachnet.com/~hstiles/cardtype.html</a></p>
Validating Emails (PHP)
2011-06-13T15:10:47-07:00Jonathan Fenechhttp://code.activestate.com/recipes/users/4169413/http://code.activestate.com/recipes/577198-validating-emails/
<p style="color: grey">
PHP
recipe 577198
by <a href="/recipes/users/4169413/">Jonathan Fenech</a>
(<a href="/recipes/tags/emails/">emails</a>, <a href="/recipes/tags/validating/">validating</a>).
Revision 2.
</p>
<p>a small script that can be used for Validating Emails on </p>
<ul>
<li>Login pages</li>
<li>forums </li>
</ul>
<p>changed to preg_match from eregi function. now scripted validates everything typed in input boxes </p>
<p>Old Code = </p>
<pre class="prettyprint"><code> foreach($Email as $Emails)
{ // checks Emails - .net , .com , .au & etc
if(eregi("[a-zA-Z0-9]@+[a-z].{1,}com$",trim($Emails))|| eregi(
"[a-zA-Z0-9]@+[a-z].{1,}net$",trim($Emails)))
</code></pre>
<p>New Code = </p>
<pre class="prettyprint"><code> foreach($Email as $Emails)
{ // checks Emails - .net , .com , .au & etc
if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z]
[0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $Emails))
</code></pre>
<p>i changed from eregi function to preg_match function because eregi was taking out of PHP version 5.3.0 and 5.3.5.</p>