N
N
Never Ever2020-01-20 18:13:35
PHP
Never Ever, 2020-01-20 18:13:35

Why doesn't the regular expression work correctly?

There is such a routine.
\b^[1|3|5][a-zA-Z0-9][^O0]{3,10}\b
It checks a word for something that can only start with 1,3,5, can contain digits and letters except 0 and O with size from 3 to 10.
It works ALMOST correctly. The problem is that when you put on the second element after the numbers (1,3,5) ( 0 or O) it passes validation if you put in other places it will work as it should.
What could be the problem ?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dodo512, 2020-01-20
@Target1

/^[135]((?![o0])[a-z\d]){3,10}$/i

D
Dmitriy, 2020-01-20
@dmitriyuvin

So your second character can be 0 (zero) or O (letter O).
az and AZ this includes O and o.
0-9 enters 0 here, so it goes through.
\b^[1|3|5][a-zA-Z0-9[^O0]]{3,10}\b
Try like this

A
AUser0, 2020-01-20
@AUser0

We exclude O, o and 0 from the list of allowed characters - we get this:
\b^[135][a-np-zA-NP-Z1-9]{3,10}\b

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question