- Impact
- 109
Hi all,
Just a small simple snippet to return whether or not irregular characters (anything not on your keyboard) have been used in a string.
Very useful for rejecting international characters (Generally from bots, SPAM!). I use it to reduce spam for the registration process in my forum hosting system.
Hope someone finds it useful... Thank god for regular expressions.
If there is a more optimized way to match regular characters only, i'd love to know!
-Rhett.
Just a small simple snippet to return whether or not irregular characters (anything not on your keyboard) have been used in a string.
Very useful for rejecting international characters (Generally from bots, SPAM!). I use it to reduce spam for the registration process in my forum hosting system.
Code:
function isRegular($string)
{
return !preg_match('/[^A-Za-z0-9\s~`!@#$%^&*()-_=+{}:";\'<>?,.\/]/', $string);
}
If there is a more optimized way to match regular characters only, i'd love to know!
-Rhett.
Last edited: