|
[x]
Posted via EE Mobile
|
|
| Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
|
|
|
|
Asked by eparampa in PHP Scripting Language
We are validating input characters in our php pages. Following is the code we have written to accomplish this. Since our input boxes should accept special characters like ÀÁetc., we have used mb_strpos function. But the problem is, if the function could not find a string's position (this meant, the character is invalid), it returns empty string. The application is treating the empty string as "0"(zero) and allows invalid character.
Experts, Kindly guide us whether we are doing the correct coding to accomplish our desired task.
Thanks,
eprm.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
|
$StringValue = "abcdefghijklmnopqrstuvwxyz0123456789_-.@ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ()'&/ ";
$value = $_POST["txtName"];
for($i=0; $i < strlen(utf8_decode($value)); $i++)
{
$char_pos=0;
$char_sub=mb_substr($value, $i, 1,'UTF-8');
$char_pos=mb_strpos($StringValue, $char_sub, 0,'UTF-8');
if(($char_pos) >= 0)
{
echo 'VALID Char';
}
else
{
echo 'Invalid Characters found';
}
}
|
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625