-2
I have an input where the user informs several product codes, and the system returns a list.
But I need to validate the string
that is to check this exactly as: 132,234,14,56
That is, each code separated by a comma.
I tried to do it that way, but it didn’t work:
if (preg_match('/^,/', $ids)) {
echo "erro nas informações";
}
OBS: It has to be always integer numbers, separated by , can not end with , can not contain letters nor space.
Your question is not clear enough, try to give more details.
– Marconi
Are only 4 codes? Are they always 4 codes? Does the number of digits vary? Can you end with
,
? Can you have spaces? Can you have letters? These, for example, are some of the basic things that make all the difference when answering.– Bacco
no, the user can enter as many codes as he wants
– Hugo Borges
The other questions I asked in the comment are important too. Although apparently these requirements are to solve some other problem in other parts of your code, then the right solution would not be the one you are asking, but at least putting all the details in the question can help you get the answer you expect.
– Bacco
Sorry, I really did not know how to express myself in this question. Well come on. It has to be always whole numbers, separated by
,
cannot end with the,
may not contain letters or space.– Hugo Borges
@Hugoborges search [Dit] the question with this information and some more varied examples than can and cannot. Not everyone reads the comments. This "bureaucracy" that we ask is to help you get where you want, and to avoid that the people waste time responding and the solution does not solve your problem. If you can make the question very clear, it’s easy for the community to vote to reopen the question (and possibly improve the vote). The intention is always to help, but it takes this "Investment" on your part to make the problem as clear as possible.
– Bacco
ok I’ve done it ;) vlw
– Hugo Borges