0

Looking for some help on how to validate a string in PHP.

My string contains:

  • 4 NUMBER
  • 1 LETTER
  • 5 NUMBER

all in one entry, so like 1234A12345.

I need to make sure/validate this before inserting in the DB.

Can one of the wizard help me out there?

1 Answer 1

3

This is a pretty simple regex:

/^\d{4}[a-zA-Z]\d{5}$/

And in case you haven't used regex in PHP before.

Sign up to request clarification or add additional context in comments.

2 Comments

code $regex = '/\d{4}[a-zA-Z]\d{5}/'; if (!preg_match($regex, $myref)) { die('Please ensure the reference you enter is in the correct format.'); } code
@SaloCine: You can indicate code inline by surrounding it with backticks (`), like this (actual text looks like `like this`).

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.