Use end of line anchor $
also to avoid matching unwanted input:
preg_match('/^[\p{L}\p{N}_-]+$/u', $test);
Вопрос
So - for a registration form (username field) I want to allow alphabet characters, numbers, underscores and dashes. The issue is -> user should be able to use their native alphabets, not just latin. So Cyrillic and other characters should be allowed.... but not chars like: $%^*() etc.
<?php
$test = 'dshfjfj_-7685гдежзи $@@@@@';
echo preg_match('/^[\pL\pN_-]+/u', $test);
?>
^ above regex results in true, even though I don't wanna allow @
-> what am I doing wrong?
Решение
Use end of line anchor $
also to avoid matching unwanted input:
preg_match('/^[\p{L}\p{N}_-]+$/u', $test);