Solved

check my variables with this regex? 1[0-9]{6}[xX0-9]{1}

Posted on 2008-06-17
6
262 Views
Last Modified: 2010-04-21
Hi

I'm moving some code from Java to PHP and I have a variable (  $paymentReference1  ) that I need to check againse this regex (  1[0-9]{6}[xX0-9]{1}  )

Can someone show me what to do please and possible explain the regex a little

Many thanks
Neil
0
Comment
Question by:NeilT
  • 3
  • 2
6 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 21800614
perl -MYAPE::Regex::Explain -e "print YAPE::Regex::Explain->new(qr(1[0-9]{6}[xX0-9]{1}))->explain"
The regular expression:

(?-imsx:1[0-9]{6}[xX0-9]{1})

matches as follows:
 
NODE                     EXPLANATION
----------------------------------------------------------------------
(?-imsx:                 group, but do not capture (case-sensitive)
                         (with ^ and $ matching normally) (with . not
                         matching \n) (matching whitespace and #
                         normally):
----------------------------------------------------------------------
  1                        '1'
----------------------------------------------------------------------
  [0-9]{6}                 any character of: '0' to '9' (6 times)
----------------------------------------------------------------------
  [xX0-9]{1}               any character of: 'x', 'X', '0' to '9' (1
                           times)
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------
0
 
LVL 5

Assisted Solution

by:mms_master
mms_master earned 250 total points
ID: 21800623
Hi,

Im assuming regex is a regular expression function in java. The PHP equivelant would be ereg() and eregi(); ereg is case sensitive and eregi isnt. More info at the links below.

ereg():
http://uk.php.net/manual/en/function.ereg.php

eregi():
http://uk.php.net/manual/en/function.eregi.php

Theres an example below of how you can use them.

mms_master
<?php
 

$paymentReference1 = "10257929";
 

if (ereg("1[0-9]{6}[xX0-9]{1}", $paymentReference1)) {

    echo "They match!";

} else {

    echo "They don't match!";

}
 

?>

Open in new window

0
 
LVL 5

Expert Comment

by:mms_master
ID: 21800676
Here is a guide for regular expressions:
http://www.zytrax.com/tech/web/regex.htm

mms_master
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:NeilT
ID: 21802634
Still cant get this to work, probably doing something wrong

Using as a test:

This should come back as pass
error_log(ereg("10948055", "1[0-9]{6}[xX0-9]{1}"));

This should Fail
error_log(ereg("50948055", "1[0-9]{6}[xX0-9]{1}"));

Neither seem to do anything?

Neil



0
 
LVL 3

Author Comment

by:NeilT
ID: 21802993
got it, used preg_match in the end
0
 
LVL 3

Author Closing Comment

by:NeilT
ID: 31467877
Thanks
Neil
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
get domain with php 7 20
Problem sending file attachments 8 24
PHP get array item with custom id 4 24
Need assistance with TXT file export.  While Loop has issue. 1 17
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now