![]() |
How do you check for more than 1 letter for a variable?
How do you check to make sure that a variable only allows 1 letter or number? Here is the variable I am using in the php file:
Code:
$vbulletin->GPC['letter'] I want to do a check to make sure only one letter or number is entered. Right now you can enter anything for it. |
Quote:
PHP Code:
|
You are the man! Thank you!
I was way off on the regex as I suck at those. Here is what I ended up using: Code:
if (!(strlen($vbulletin->GPC['letter']) == 1) && preg_match('/^[a-zA-Z0-9]+$/', $vbulletin->GPC['letter'])) I will be using a different stop message, but I wanted to make sure I could get it to work first. I have another condition before this one that checks to make sure all 3 variables (letter + 2 others) are not blank. I was going to add this to that but I wanted to catch the letter variable separately. This is how it all looks together for the error checking: Code:
if (!$vbulletin->GPC['quote'] OR !$vbulletin->GPC['name'] OR !$vbulletin->GPC['letter']) If you have any suggestion s or advice, I am all ears. And thank you again. ;) |
If you are going to split it up and give messages I'd do something like this and split it a bit more, otherwise the user might get confused with one message for multiple conditions.
PHP Code:
|
Couldn't you do elseif's there also?
|
You could use an elseif if you want. I normally would do it differently. I would usually add the errors to a variable then output the variable, that way all the errors are shown at once instead of the user having to submit 3 times before he see's all the errors.
|
I've never done it with a variable like that. Can you give me an example how I could do that?
|
Something like this should suffice.
PHP Code:
|
Thanks. I'll play with that and see what I can come up with.
|
All times are GMT. The time now is 08:00 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|