PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$text = "onlyalphanumericcharacters012345";
if (ereg('[^A-Za-z0-9]', $text)) {
echo "This contains characters other than letters and numbers";
}
else {
echo "This contains only letters and numbers";
}
but the problem here is - i want the code only accept with these kind of combination: -
a) alphabet + number
b) alphabet + symbol
c) number + symbol
// Check the test entered for all the three combinations
$alpha_numeric = ereg('[^A-Za-z0-9]', $text); // alphanumeric check
$alpha_symbol = ereg('[0-9]', $text); // symbol+alphabet check
$num_symbol = ereg('[A-Za-z]', $text); // symbol+number check
// Executes if any match found
if (!$alpha_numeric || !$alpha_symbol || !$num_symbol)
{
echo "<center><font color='#FF0000'>Entered string is valid :: </font>".$text."</center><br>";
}
// else execute
else
{
echo "<center><font color='#FF0000'>Invalid text entered ::</font> ".$text;
}
Hope this helps you..
first of all, thanks for the code... maybe my question is not very clear... let me explain once again...
what i really want is the code that can check where the input must have
a) must have Alphabet + must have Number (if the input only one of these two, it will return false)
b) must have Alphabet + must have Symbol (the condition same as A(above))
c) must have Number + must have Symbol (the condition same as A(above))
as for the Symbol, im not sure what is the basic one that usually been used by other website but i know some of them accept symbol as password characters to increase security (hard for hacker to guess the password)
Your question doesn't really make sense to me. Are you saying that the input must have either alphabet + number, OR alphabet + symbol OR number + symbol? Or are you saying that it must meet all of those conditions. Either way, you chose a strange way to ask your question.
The Ninja Space Goat wrote:Your question doesn't really make sense to me. Are you saying that the input must have either alphabet + number, OR alphabet + symbol OR number + symbol? Or are you saying that it must meet all of those conditions. Either way, you chose a strange way to ask your question.
Again, what is accepted as a symbol? There are a lot of characters in the UNICODE character set.
The smartest way would be to check if there is at least one letter, one number, and one symbol, then add up the boolean results (true = 1, false = 0), then check if that is more than or equal to 2.
superdezign wrote:Again, what is accepted as a symbol? There are a lot of characters in the UNICODE character set.
The smartest way would be to check if there is at least one letter, one number, and one symbol, then add up the boolean results (true = 1, false = 0), then check if that is more than or equal to 2.
mmm... lets take something simple like ~`!@#$%^&*()-_+={}[];:<>?/., would this be alright?
When using UTF-8 and preg for one project I seem to remember I had to set the mb_internal_coding to UTF-8. Probably not relevant here but as UTF-8 has been mentioned thought I would point it out.