PHP check specific characters

3

I've created a formula that allows you to create such codes

12345-6789-101112

What I want now is, when I validate the form I want to verify that the code is correct for example.

Se contem 5(00000) em cada 3(00000-00000-00000).

Is there any way to do this?

    
asked by anonymous 29.03.2018 / 19:14

1 answer

2

One way is to use a regular expression to validate the specific format. % with% siginica that only letters (a-z) and numbers (0-9) will enter the capture.

$str = '12345-67819-10111';
$regex = '/^[a-z0-9]{5}-[a-z0-9]{5}-[a-z0-9]{5}$/i';

$valido = preg_match($regex, $str);
    
29.03.2018 / 19:24