Can you help me to build a better regex for me? I'm now making telegram bot, and it gather user input to check their proposal status. I need to validate their input with preg_match
.
example reference number:
11/A-9/XI/2015
12/A-9/XII/2.99/2015
I'm not doing anything yet, but i consider using preg_match
to ensure the input contains some character. Here is my code:
preg_match("#[0-9A-Za-z./]#", $text);
Any better solutions?
You could use this based on your string:
^[0-9]{1,2}\/[a-zA-Z]-[0-9]\/[A-Z]+\/([0-9.]+\/)?[0-9]+$
It would match 12/A-9/XII/2015
and 12/A-9/XII/2.99/2015
but not a12/A-9/XII/2.99/2015
, 12/A-9/XII/a2.99/2015
or 12/A-9/XII/2.99/2015a
See it live and the explanation here