Forum Moderators: coopster

Message Too Old, No Replies

ereg to preg match

ereg to preg

         

zpupster

5:08 pm on Feb 1, 2015 (gmt 0)

10+ Year Member



if (ereg ("(^[0-9][0-9][0-9]$|^[0-9][0-9][0-9][0-9]$)", $HTTP_POST_VARS['cvv_number']) == 1){


this ereg needs to e changed to
preg_match

i have done some of these with single quotes and commas i.e./,/
i do not know how to do this with double quotes

lucy24

7:26 pm on Feb 1, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Psst!
(^[0-9][0-9][0-9]$|^[0-9][0-9][0-9][0-9]$)
=
^\d\d\d\d?$
=
^\d{3,4}$

penders

7:31 pm on Feb 1, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



i have done some of these with single quotes and commas i.e./,/
i do not know how to do this with double quotes


In this case it's exactly the same for double quotes. (Commas?)

You could simply "convert" this by adding the regex delimiters "/" on either end. But you might as well simplify the regex at the same time (which you could have done with POSIX regex as well). You are matching a 3 or 4 digit number.

if (preg_match('/^\d{3,4}$/', $_POST['cvv_number'])) {


If you are in the process of updating your code then consider changing $HTTP_POST_VARS as well, which is also deprecated.