Old 22-12-2007, 22:47   #1 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Another Validation

SOrry for all these validations! I promise this will be the last one!

This one is for credit cards. I looked up all these things on google and non that were very useful for me.

PHP Code:
else if($typecard == 'mastercard') { if (!preg_match("/^(5[1-5])+([0-9]{14})$/s"$ccard)) 
            
$errmsg 'Please enter a vaild Mastercard card number';
    }  
    else if(
$typecard == 'visa') { if (!preg_match("/^(4)+([0-9]{12-15})$/s"$ccard)) 
            
$errmsg 'Please enter a vaild Visa card number';
    }
    else if(
$typecard == 'americanexpress') { if (!preg_match("/^(34|37{2})+([0-9]{13})$/s"$ccard)) 
            
$errmsg 'Please enter a vaild American Express card number';
    } 

I came up with this. But it doesnt work... no wonder since I made it. Soo im trying to write a statment where IF the type of card equals = CARD VALUE then CARD NUMBER must = XXXXXXXXXXXX.... How do you write a "then" in php? echo?... HELP ME!
  Reply With Quote
Old 23-12-2007, 02:39   #2 (permalink)
iblastoff
gotsa a malanga!
 
iblastoff's Avatar
 
Join Date: Apr 2006
Location: ottawa, canada
Posts: 489
err not why something like (didn't check your regex or anything)
PHP Code:
else if(($typecard == 'mastercard') && (!preg_match("/^(5[1-5])+([0-9]{14})$/s"$ccard))) {

/*do whatever you need to do */
            
} else { 
$errmsg 'Please enter a vaild Mastercard card number';

__________________
  Reply With Quote
Old 23-12-2007, 12:37   #3 (permalink)
John Good
+
 
John Good's Avatar
 
Join Date: May 2005
Location: Tropical Networks
Posts: 1,584
how you people can deal with regular expressions is a mystery to me
__________________
Fonts are like cologne: A bad choice speaks louder than a good one. Justin Feinstein
  Reply With Quote
Old 23-12-2007, 19:32   #4 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
PHP Code:
else if(($typecard == 'mastercard')  &&  ("/^(5[1-5])+([0-9]{14})$/s" != $ccard)) {
            
$errmsg 'Please enter a vaild Mastercard card number';
    }  
    else if((
$typecard == 'visa') && ("/^(4)+([0-9]{12-15})$/s" != $ccard)) { 
            
$errmsg 'Please enter a vaild Visa card number';
    }
    else if((
$typecard == 'americanexpress') && ("/^(34|37{2})+([0-9]{13})$/s" != $ccard)) {
            
$errmsg 'Please enter a vaild American Express card number';
    } 

I have all my values right.. and everything. Can anyone explain my error in this code? since it doesnt work... hmmmmmx. Any help to make this work is appriciated! The validation completely skips this code and this code does nothing... even with letters in the text field! Help please =)!!
  Reply With Quote
Old 23-12-2007, 20:20   #5 (permalink)
jcharnley
Registered User
 
jcharnley's Avatar
 
Join Date: Dec 2007
Location: Denmark 4600
Posts: 82
Cant you write the error msg? Usually the php gives you a msg like "on line 344, blah blah blah" ...
  Reply With Quote
Old 23-12-2007, 20:24   #6 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
There is no error message. the php is fine. its just not working at all. It just skips over this php and goes to the other validations.
  Reply With Quote
Old 23-12-2007, 20:33   #7 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
My $typecard is a select field. Soo there are only those 3 options.

HTML Code:
<select name="typecard" id="typecard" class="style6"> <option value ="mastercard" selected="selected">Mastercard</option> <option value ="visa">Visa</option> <option value ="americanexpress">American Express</option> </select>

Might I have to add something to this? or change my php to incorporate this?
  Reply With Quote
Old 23-12-2007, 20:38   #8 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
OHHHHH SOOOO STUPID! OMFG! seriously. I spent a whole crap load of hours and just found out my php was like this:

PHP Code:
$typecard  $_POST['typecard ']; 

with that stupid space between typecard and ' ...... GRRRRRRR

thanks for the help guys!. happy holidays. =)
  Reply With Quote
Old 23-12-2007, 21:11   #9 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
New problem I can't seem to solve...

PHP Code:
else if(($typecard == 'mastercard')  &&  ("/^[51|52|53|54|55]{2}[0-9]{14}$/s" != $ccard)) {
            
$errmsg 'Please enter a vaild Mastercard card number';
    }  
    else if((
$typecard == 'visa') && ("/^[4]{1}[0-9]{12,15}$/s" != $ccard)) { 
            
$errmsg 'Please enter a vaild Visa card number';
    }
    else if((
$typecard == 'americanexpress') && ("/^[34|37]{2}[0-9]{13}$/s" != $ccard)) {
            
$errmsg 'Please enter a vaild American Express card number';
    } 

When I put in a test which configures to a vaild creditcard. It says its invalid! ???!!! for visa I tried 4000000000000 and that should show as valid. And for mastercard I tried 5100000000000000. These didnt work!!
  Reply With Quote
Old 23-12-2007, 21:25   #10 (permalink)
Hunch
Grumpy old man
 
Hunch's Avatar
 
Join Date: Oct 2007
Location: North Japan
Posts: 1,695
Quote:
Originally Posted by John Good
how you people can deal with regular expressions is a mystery to me

They're pretty straightforward when you break them down into the individual parts. They just look intimidating when you see that long string of gibberish like: /<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>/ (this one matches opening and closing pairs of HTML tags by the way). It's really worth learning the syntax because regexs are enormously powerful, and brilliantly efficient.

To use an analogy, I think of it in the same way as a mixing desk in a recording studio. A long long time ago I studied sound engineering and had a part time job in a studio. Our main desk at the time was a 64 channel affair which like the desks in many studio control rooms gave a lot of visitors that 'bloody hell, how do you understand that thing?' kind of vibe.



It looks intimidating until you realize that the vast majority of the desk is just exactly the same row of buttons duplicated 64 times. Even though it's plainly obvious, a lot of people just look at it and don't see that because they're overwhelmed by the apparent complexity of what is in front of them. You learn how to use one channel strip, and you've mastered 90% of what the desk does. In the same way, regular expressions, while not quite the same as a mixing desk, are just a bunch of symbols which carry out fairly simple functions but when combined, can appear unintelligible. Once you can understand the basic principles, reading and constructing regexs is a lot simpler than it looks.
  Reply With Quote
Old 23-12-2007, 21:46   #11 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Thanks for that hunch!! nice... Ive got the basic idea =) and I fixed my problem by using !pre_match. But now im confused with this

PHP Code:
("/^[4][0-9]{12,15}$/s"

Because is means, the first number is a 4, then there must be 12 or 15 numbers between 0-9 after the 4. For some reason its working like 12-15. So insted of a number 12 or 15 digits long, it works as a number between 12 and 15 digits. Including 13 and 14 digits... ? is this what its suppost to do? because I put in 4 + 6 other digits, invalid! perfect. Then 4 + 12 other digits, vaild! perfect. then 4 + 14 digits, vaild!? not perfect!!!. and then 15 digits is vaild and after 15 its not which is correct. But why is it vaild with 13 and 14 digits??? shouldnt the comma ',' make it 12 or 15 and not between 12 and 15!.
  Reply With Quote
Old 23-12-2007, 22:23   #12 (permalink)
Cborrow
I like code.
 
Join Date: Dec 2004
Location: Chesapeake, VA
Posts: 229
Send a message via AIM to Cborrow
Yes {12,15} matches anything bewteen 12 and 15 chacters long.

Though this will match ones that are either 12 or 15 numbers long, no more, no less.

Code:
[4]([0-9]{15}|[0-9]{12})
__________________
Code { for thought }
"My programs never have bugs, they just develop random features."
  Reply With Quote
Old 23-12-2007, 22:54   #13 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
ok thanks Cborrow! I thought "," would be OR... and I also thought {12|15} would work but it sure doesnt.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8