Forum Moderators: coopster
I'm a little lost here: I need to make sure a string does not contain anythin except aphanumerics (and only one space, not two together).
So, nick w is okay butnick<3 spaces>w is not.
nick* is not okay and ~~nick~~ isn't either, see what I mean?
I've got this far:
if (!ereg('[[:alnum:]]', $string)) {
$errors[]="Please use only alphanumeric characters";
}
But it only kinda works, I've read the manual page a couple of times for ereg and it just won't sink in.
Anyone help me out a litte?
Thanks....
Nick
Still having a little bother:
if (!preg_match('[^A-Za-z0-9 ]', $string)) {
$errors[]="Please use only alphanumeric characters";
}
Is still assigning the error when I do "nick w"
Basically, I need it to work with usernames, so they might contain a space anywhere in the string (although i'll trim() the ends).
Can you spot what I need here?
Nick
if (!preg_match('[^A-Za-z0-9 ]', $string)) {
$errors[]="Please use only alphanumeric characters";
}
if (preg_match [php.net](' ', $string)) {
$errors[]="Too many spaces!";
}