hi wapmasters , can anybody tell me how can i allow only english test to be entered into a text box or, if a text is entered in any other language how can i replace it with a blank space or empty string ?
thanx
Started on the old forum in June 2011 · view the original in the archive · old links redirect here
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
hi wapmasters , can anybody tell me how can i allow only english test to be entered into a text box or, if a text is entered in any other language how can i replace it with a blank space or empty string ?
thanx
u need an english dictionary to test all possible values
no no .. i don't want to test it is a valid english word or not. i just want to test whether the string contains only "a-z,A-Z and other symbols" means it should not be using arabic,chinese or other such characters . What i want to block is something like this مقاطع سكس
thanx
ok thats what you ment
use regular expressions
$word = isset($_POST['word']) ? trim($_POST['word']) : '';
if(!preg_match("#^([a-zA-Z0-9_-+]+)$#", $word, $m))
{
echo "invalid characters supplied";
}
else
{
print_r($m); //matches that were found
}
Your welcome a better way to do this though to prevent mix characters
$error = 0;
$word = isset($_POST['word']) trim($_POST['word']) : '';
for($i=0; $i<=strlen($word); $i++)
{
if(!preg_match("/([a-zA-Z0-9_-+])/", $word[$i], $m))
{
break;
$error = 1;
}
}
if($error==1)
{
echo "incorrect word only aphanumeric chars";
}
else
{
echo "you have passed the test";
}
//end
antony2kx wrote: Your welcome a better way to do this though to prevent mix characters
$error = 0; $word = isset($_POST['word']) trim($_POST['word']) : ''; for($i=0; $i<=strlen($word); $i++) { if(!preg_match("/([a-zA-Z0-9_-+])/", $word[$i], $m)) { break; $error = 1; } } if($error==1) { echo "incorrect word only aphanumeric chars"; } else { echo "you have passed the test"; } //end
So if someone types a word in Serbian "zdravo" which means "hello" in English will pass the filter. Also, if someone writes "hello, how are you?" will not pass the filter. o.O
Try this:
$pspell_link = pspell_new("en");
$word = explode(" ", $message);
foreach($word as $k => $v) {
if (pspell_check($pspell_link, $v)) {
echo "spelled right";
} else {
echo "Sorry, wrong spelling";
};
};
If you look clearly at what help was wanted you would have seen that the code i have written is exactly what was asked for, if he wanted english statements then i could have inlcuded commas etc, but what was was asked for is that the text box should only accept a-zA-z0-9, juts look keenly before you reply.
even though zdravo is sebian its still alpha chars so it would pass,
what this code really works good on is that it helps to prevent other special chars, like russian etc.
antony2kx wrote: If you look clearly at what help was wanted you would have seen that the code i have written is exactly what was asked for, if he wanted english statements then i could have inlcuded commas etc, but what was was asked for is that the text box should only accept a-zA-z0-9, juts look keenly before you reply.
even though zdravo is sebian its still alpha chars so it would pass,
what this code really works good on is that it helps to prevent other special chars, like russian etc.
Me? Do u understand english well? Here is what he asked:
"hi wapmasters , can anybody tell me how can i allow only english test to be entered into a text box or, if a text is entered in any other language how can i replace it with a blank space or empty string ?
thanx"
He did not asked for that what u have posted. Period.
dude the guy ment a-z 0-9 only so just relax, cant you see he said thanks that it worked for him, why are you cursing, dont brag, if i never knew english i owuld not be doing my masters now in computer engineering science and i am just 20; lol
antony2kx wrote: dude the guy ment a-z 0-9 only so just relax, cant you see he said thanks that it worked for him, why are you cursing, dont brag, if i never knew english i owuld not be doing my masters now in computer engineering science and i am just 20; lol
This is what he ment with "only in english":
$pspell_link = pspell_new("en");
$word = explode(" ", $message);
foreach($word as $k => $v) {
if (pspell_check($pspell_link, $v)) {
echo "spelled right";
} else {
echo "Sorry, wrong spelling";
};
};
You, please, leave me alone, don't explain anything more. I do not want to discuss with you on this issue, but it seems that you just want to argue. Cheers.
all the wapmasters, thanx for your help. . What i needed was a basic idea on how to do it , i can easily mod it out. By the way arnage that snippet was very helpful and i am gonna implement that.. Thanx