NameSilo

Checking for certain chars?

Spacemail by SpaceshipSpacemail by Spaceship
Watch
Impact
19
Hey
Can anyone help me do this:

I am trying to check for specific characters in a string..and if they are there...i want it to give an error...i want to check the string "$username" and check for everything that is not a alphanumberical char...

so if it contains ";" or "," or ":" or "}" etc..i want it to give an error
can anyone help me out...
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
PHP:
<?php

if (preg_match("/([^a-z0-9]+)/i", $string))
{
    die('Error: string can only contain letters (a-z) and numbers (0-9)');
}

?>
 
0
•••
SecondVersion said:
PHP:
<?php

if (preg_match("/([^a-z0-9]+)/i", $string))
{
    die('Error: string can only contain letters (a-z) and numbers (0-9)');
}

?>

don't you need the ! in !preg_match?
 
0
•••
No, he did ([^... the ^ means not those characters.
 
0
•••
Appraise.net

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back