Jump to content

Strings that only have a-z 1-9 _-.


monkeytooth

Recommended Posts

Yes, You'd use a Regular Expression ( REGEX ) pattern to find if a string contains certain characters. You can perform one like so:

 

function CheckString($str) 
{
  if (preg_match('~[^a-zA-Z0-9\-_.]~', $str)) {
     echo "String is VALID;" //1
  } else { 
     echo "STRING CONTAINS INVALID CHARACTERS" //0
  }
}

$txt = "A-Z-0_2_3_4_5";
$txt2 = "0-F-*-@-K";
CheckString($txt);
CheckString($txt2);

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.