IT.COM

Remove irregular characters

Spaceship Spaceship
Watch

BillyConnite

<img src="images/smilies/biggrin.gif" border="0" cVIP Member
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.

Code:
	function isRegular($string)
	{
		return !preg_match('/[^A-Za-z0-9\s~`!@#$%^&*()-_=+{}:";\'<>?,.\/]/', $string);
	}
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.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Updated the match, forgot to include to allow spaces :red:
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back