Hey there, im making a user registration..
Is there a way to make it check that it is only letters and spaces being submitted?
The name cannot contain any special characters.
Let me know
Thanks
Hey there, im making a user registration..
Is there a way to make it check that it is only letters and spaces being submitted?
The name cannot contain any special characters.
Let me know
Thanks
I was working on the same thing, and I got confused.
I don't know regular expressions very well.
Here's what I came up with:
$name = ereg_replace('[^a-zA-Z0-9]','',$name);
That SHOULD be 'replace any instances of not (lowercase, uppercase and numbers) with nothing.
But it doesn't work. Without the ^, it works, but in the opposite way, taking out all letters/numbers.
Note: remove 0-9 if you won't want to allow numbers.
I think someone else should be able to figure this out. I just haven't found an answer yet.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
A quick something I came up with, not tested it much, but it worked if the name contained either a number, _, ?, # or ^.
To use just add more characters between []: $pattern = "/([0-9_?#^])+/";PHP Code:$name = $_POST['name'];
$pattern = "/([0-9_?#^])+/"; // Add more illegal characters here...
$badname = preg_match($pattern, $name); // Will return 0 if no characters are found...
if ($badname!='0'){
// Name contains some illegal characters...
echo 'The name must only contain letters and spaces...';
}
else {
// The name only contains letters and spaces, do whatever...
echo 'Name didn\'t container illgeal characters...';
}
That's ineffective, though. Even using all of the characters on the keyboard, something else might be entered. You really need a list generated as what CAN be included, not what can't.
Anyway, this is a more extensive character list:
'[!0-9#$%&\'()*+,-./ :;?@\`{|}~^"]'
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Thanks for everything guys!![]()
Bookmarks