0

I want to match a string using REGEX which follows the syntax:

Text/number

So my preg_match() function is...

if(preg_match("/[^A-Za-z/0-9]$/ ", $folio))
$err[] = "Wrong value, it's should be lik: C/455";

But getting error message...

4 Answers 4

1

Try this:

$folio = "Text/15";
if(preg_match('~[a-z]/[\d]~i', $folio))
    echo "match";
else
    echo "no match";
Sign up to request clarification or add additional context in comments.

2 Comments

i think you need to escape the '/', i.e. replace with //
@MukeshSoni No, because I use ~ as prefix/suffix
1

You needed to escape / using \. Also numbers is a subset of text and you need to include it in your text part. You need one or more text/numeric characters, so a + is required.

It adds up to the following statement:

if(preg_match("/^[A-Za-z0-9]+\/[0-9]+$/", $folio))

Comments

0

You either need to escape / or use different char to surround regexp, for example:

if(preg_match("@[^A-Za-z/0-9]$@ ", $folio))

Comments

-1
if ( ! preg_match('/\b[a-z]+\/[0-9]+\b/i', $folio)) {
  $err[] = "Wrong value, it's should be like this: C/455";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.