Hey there!
I have this preg_match()
to check if there are symbols in password
if(!preg_match('/[^0-9a-zA-z]/', $password)){echo 'There are no symbols';}
but if user makes password like RAndom_33 it says there are no symbol till now other symbols worked!
Why could this happen?
You need to add _
at the end of your regex.
@spaceshiptrooper @chorn Sorry for late replay! It seems that it still says that symbols was not used
[A-z]
is a weird range âŠ
SamA74
April 26, 2018, 2:30pm
8
Not in isolation, but used in combination with a-z
is weird. I guess itâs a typo.
Trying things out on an on-line regex tester, Iâm having a hard time getting it to recognise underscores. Not sure why, I wasnât aware of anything special about them in regex.
I would prefer \W
for that anyways.
1 Like
If you are using other characters too, you have to put them in there too. If you donât, itâll say it isnât in there.
I think itâs precisely because the range is A-z that the underscore isnât being considered a âsymbolâ.
The ASCII characters A-Z range from decimal 65-90. The ASCII characters a-z range from decimal 97-122. The characters ` ^_`` range from decimal 91-96.
In other words the underscore falls with the range A-z
4 Likes
SamA74
April 26, 2018, 7:06pm
12
That would explain the problem I was having, if I copied the regex, but had not noticed the typo.
But I just found that \W
considers an underscore a word character, so maybe the 1-9a-zA-Z
would be better and the problem was the typo all along.
1 Like
The only potential problem with the âword characterâ escape is itâs based on locale. So for example the âñâ in señor wouldnât match an ânâ.
But only when used with the u
(PCRE_UTF8) modifier.
1 Like
system
Closed
July 27, 2018, 1:40pm
15
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.