This is a match:
preg_match('/[a-bA-B0-9]+/', 'username')
But this is not:
preg_match('/^[a-bA-B0-9]+$/', 'username')
Why is that?
This is a match:
preg_match('/[a-bA-B0-9]+/', 'username')
But this is not:
preg_match('/^[a-bA-B0-9]+$/', 'username')
Why is that?
Are you testing the actual literal 'username'
?
/[a-bA-B0-9]+/
will test the existence of a,b,A,B,0,1,2,3,4,5,6,7,8,9 anywhere in the string. So it will match abBa854Abba32
, and it will match sjfsgfafnvesv
.
/^[a-bA-B0-9]+$/
will test that the enitre string is made of a,b,A,B,0,1,2,3,4,5,6,7,8,9. So it will match abBa854Abba32
, and it will not match sjfsgfafnvesv
.
Perhaps you meant /^[a-zA-Z0-9]+$/
.