Hello all.
I have a string that will contain the username, for the security reasons i want it to be checked it if its diferent from the specific charset.
I think it could be done by looping the check 1 character from the username at a time till the end of it, but is there any faster way to do it?
For example:
$charset="abcd1234";
$string1="312";
$string2="5abc";
It should return that $string2 is not contained in the charset.
Thanks in advance.

Recommended Answers

All 4 Replies

Hello all.
I have a string that will contain the username, for the security reasons i want it to be checked it if its diferent from the specific charset.
I think it could be done by looping the check 1 character from the username at a time till the end of it, but is there any faster way to do it?
For example:
$charset="abcd1234";
$string1="312";
$string2="5abc";
It should return that $string2 is not contained in the charset.
Thanks in advance.

http://php.net/preg_match That is all

Regular Expressions is what you're looking for. As ShawnCplus said, preg_match() is the function you'll want to use. You might want to do some reading on regular expressions. I used this tutorial a while ago:
http://www.regular-expressions.info/tutorial.html

The problem is that the charset will not have all possible usernames.
Larger example would be :
$charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$username="abb";
$username="0000b";
$username2="_abb";
Two first are valid and the 3rd one isnt.
Err,i think im really dumb, creating a charset and trying to compare latter a latter , when i have [A-Za-z0-9]{4,10} lol =)
Ty for help.

The problem is that the charset will not have all possible usernames.
Larger example would be :
$charset="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$username="abb";
$username="0000b";
$username2="_abb";
Two first are valid and the 3rd one isnt.
Err,i think im really dumb, creating a charset and trying to compare latter a latter , when i have [A-Za-z0-9]{4,10} lol =)
Ty for help.

You're welcome =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.