Jump to content

Test string for range of characters


haku

Recommended Posts

ctype_alpha("$value") letters only

ctype_digit("$value") numbers only

ctype_alnum("$value") letters and numbers only

 

above can only equal true or false

 

 

$value="hello world";

 

if (ctype_alpha("$value")==true)

{echo "Good Job";}

else

{echo "WTF?";}

 

 

output=> Good Job

Thanks to both of you!

 

I didn't realize there is a regex section of the board. I will have to use that in the future.

 

I need a regex expression. I'm actually not testing for alphabetic characters to tell the truth, I'm testing for Japanese kana, so the three functions in the previous post wont work. But I didn't think anyone here would know how to write regex expressions for Japanese, so I'm just going to substitute from a regex expression.

Thanks for the help everyone. I managed to get my code working. I thought it would be as simple as substituting the first and last katakana (one of the Japanese alphabets) into the English regex, but it wasn't. In the end, it was this code that did it for me:

 

if (mb_ereg('[。-゚]', $string))
{
echo "string is katakana";
}
else
{
echo "string is not katakana";
}

 

I don't imagine that many people will need this code for anything, but I thought I would post it here in case someone searches for it sometime.

 

Note: This works in EUC-JP encoding. I don't know and doubt that it will work with other encodings (Shift_JIS and utf-8 for example)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.